Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

sowm: titlebars #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define CONFIG_H

#define MOD Mod4Mask
#define TH 90
#define TC 255 + (255<<8) + (255<<16)

const char* menu[] = {"dmenu_run", 0};
const char* term[] = {"st", 0};
Expand Down
59 changes: 57 additions & 2 deletions sowm.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// sowm - An itsy bitsy floating window manager.

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/XF86keysym.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>

#include "sowm.h"

Expand All @@ -31,6 +33,27 @@ static void (*events[LASTEvent])(XEvent *e) = {

#include "config.h"

void title_add(client *c) {
if (c->t) return;

XClassHint cl;
XGetClassHint(d, c->w, &cl);

if (!strcmp(cl.res_name, "no-title")) return;

win_size(c->w, &wx, &wy, &ww, &wh);
c->t = XCreateSimpleWindow(d, root, wx, wy - TH, ww, TH, 0, TC, TC);
XMapWindow(d, c->t);
}

void title_del(client *c) {
if (!c->t) return;

XUnmapWindow(d, c->t);
XDestroyWindow(d, c->t);
c->t = 0;
}

void win_focus(client *c) {
cur = c;
XSetInputFocus(d, cur->w, RevertToParent, CurrentTime);
Expand All @@ -51,6 +74,11 @@ void notify_enter(XEvent *e) {
void notify_motion(XEvent *e) {
if (!mouse.subwindow || cur->f) return;

if (mouse.subwindow == cur->t) {
mouse.subwindow = cur->w;
win_size(cur->w, &wx, &wy, &ww, &wh);
}

while(XCheckTypedEvent(d, MotionNotify, e));

int xd = e->xbutton.x_root - mouse.x_root;
Expand All @@ -61,6 +89,11 @@ void notify_motion(XEvent *e) {
wy + (mouse.button == 1 ? yd : 0),
MAX(1, ww + (mouse.button == 3 ? xd : 0)),
MAX(1, wh + (mouse.button == 3 ? yd : 0)));

if (cur->t) XMoveResizeWindow(d, cur->t,
wx + (mouse.button == 1 ? xd : 0),
wy + (mouse.button == 1 ? yd : 0) - TH,
MAX(1, ww + (mouse.button == 3 ? xd : 0)), TH);
}

void key_press(XEvent *e) {
Expand Down Expand Up @@ -117,6 +150,7 @@ void win_del(Window w) {
if (x->next) x->next->prev = x->prev;
if (x->prev) x->prev->next = x->next;

title_del(x);
free(x);
ws_save(ws);
}
Expand All @@ -130,6 +164,8 @@ void win_center(const Arg arg) {

win_size(cur->w, &(int){0}, &(int){0}, &ww, &wh);
XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2);

if (cur->t) XMoveWindow(d, cur->t, (sw - ww) / 2, (sh - wh - TH * 2) / 2);
}

void win_fs(const Arg arg) {
Expand All @@ -138,9 +174,12 @@ void win_fs(const Arg arg) {
if ((cur->f = cur->f ? 0 : 1)) {
win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh);
XMoveResizeWindow(d, cur->w, 0, 0, sw, sh);
XRaiseWindow(d, cur->w);
title_del(cur);

} else {
XMoveResizeWindow(d, cur->w, cur->wx, cur->wy, cur->ww, cur->wh);
title_add(cur);
}
}

Expand All @@ -156,6 +195,7 @@ void win_to_ws(const Arg arg) {
ws_sel(tmp);
win_del(cur->w);
XUnmapWindow(d, cur->w);
title_del(cur);
ws_save(tmp);

if (list) win_focus(list);
Expand All @@ -165,13 +205,21 @@ void win_prev(const Arg arg) {
if (!cur) return;

XRaiseWindow(d, cur->prev->w);

if (cur->prev->t)
XRaiseWindow(d, cur->prev->t);

win_focus(cur->prev);
}

void win_next(const Arg arg) {
if (!cur) return;

XRaiseWindow(d, cur->next->w);

if (cur->next->t)
XRaiseWindow(d, cur->next->t);

win_focus(cur->next);
}

Expand All @@ -183,11 +231,17 @@ void ws_go(const Arg arg) {
ws_save(ws);
ws_sel(arg.i);

for win XMapWindow(d, c->w);
for win {
XMapWindow(d, c->w);
title_add(c);
}

ws_sel(tmp);

for win XUnmapWindow(d, c->w);
for win {
XUnmapWindow(d, c->w);
title_del(c);
}

ws_sel(arg.i);

Expand Down Expand Up @@ -219,6 +273,7 @@ void map_request(XEvent *e) {

XMapWindow(d, w);
win_focus(list->prev);
title_add(cur);
}

void run(const Arg arg) {
Expand Down
4 changes: 3 additions & 1 deletion sowm.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef struct client {
struct client *next, *prev;
int f, wx, wy;
unsigned int ww, wh;
Window w;
Window w, t;
} client;

void button_press(XEvent *e);
Expand All @@ -43,6 +43,8 @@ void notify_destroy(XEvent *e);
void notify_enter(XEvent *e);
void notify_motion(XEvent *e);
void run(const Arg arg);
void title_add(client *c);
void title_del(client *c);
void win_add(Window w);
void win_center(const Arg arg);
void win_del(Window w);
Expand Down