sowm: simpler center

This commit is contained in:
Dylan Araps 2019-10-19 08:14:03 +03:00
parent b48c9b6add
commit 5c075a359a
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
2 changed files with 8 additions and 10 deletions

View File

@ -15,7 +15,7 @@ const char* colors[] = {"bud", "/home/goldie/Pictures/Wallpapers", 0};
static struct key keys[] = { static struct key keys[] = {
{MOD, XK_q, win_kill, {0}}, {MOD, XK_q, win_kill, {0}},
{MOD, XK_c, win_center, {.w = 0}}, {MOD, XK_c, win_center, {0}},
{MOD, XK_f, win_fs, {0}}, {MOD, XK_f, win_fs, {0}},
{Mod1Mask, XK_Tab, win_next, {0}}, {Mod1Mask, XK_Tab, win_next, {0}},

16
sowm.c
View File

@ -36,7 +36,7 @@ static void notify_enter(XEvent *e);
static void notify_motion(XEvent *e); static void notify_motion(XEvent *e);
static void run(const Arg arg); static void run(const Arg arg);
static void win_add(Window w); static void win_add(Window w);
static void win_center(const Arg arg); static void win_center();
static void win_del(Window w); static void win_del(Window w);
static void win_fs(); static void win_fs();
static void win_kill(); static void win_kill();
@ -168,14 +168,12 @@ void win_kill() {
if (cur) XKillClient(d, cur->w); if (cur) XKillClient(d, cur->w);
} }
void win_center(const Arg arg) { void win_center() {
Window w = arg.w ? arg.w : cur->w; if (!cur) return;
if (!w) return; win_size(cur->w, &(int){0}, &(int){0}, &ww, &wh);
win_size(w, &(int){0}, &(int){0}, &ww, &wh); XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2);
XMoveWindow(d, w, (sw - ww) / 2, (sh - wh) / 2);
} }
void win_fs() { void win_fs() {
@ -251,11 +249,11 @@ void map_request(XEvent *e) {
XSelectInput(d, w, StructureNotifyMask|EnterWindowMask); XSelectInput(d, w, StructureNotifyMask|EnterWindowMask);
win_size(w, &wx, &wy, &ww, &wh); win_size(w, &wx, &wy, &ww, &wh);
win_add(w); win_add(w);
win_focus(list->prev);
if (wx + wy == 0) win_center((Arg){.i = w}); if (wx + wy == 0) win_center();
XMapWindow(d, w); XMapWindow(d, w);
win_focus(list->prev);
} }
void run(const Arg arg) { void run(const Arg arg) {