mirror of
https://github.com/dylanaraps/sowm.git
synced 2025-05-19 01:20:23 -07:00
sowm: track current window
This commit is contained in:
parent
d6b7a98586
commit
4ed0c0919f
@ -15,7 +15,7 @@ const char* colors[] = {"bud", "/home/goldie/Pictures/Wallpapers", 0};
|
||||
|
||||
static struct key keys[] = {
|
||||
{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}},
|
||||
{Mod1Mask, XK_Tab, win_next, {0}},
|
||||
|
||||
|
63
sowm.c
63
sowm.c
@ -36,7 +36,7 @@ static void notify_enter(XEvent *e);
|
||||
static void notify_motion(XEvent *e);
|
||||
static void run(const Arg arg);
|
||||
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_fs();
|
||||
static void win_kill();
|
||||
@ -45,12 +45,12 @@ static void win_to_ws(const Arg arg);
|
||||
static void ws_go(const Arg arg);
|
||||
static int xerror() { return 0;}
|
||||
|
||||
static client *list = {0}, *ws_list[10] = {0};
|
||||
static client *list = {0}, *ws_list[10] = {0}, *cur;
|
||||
static int ws = 1, sw, sh, wx, wy;
|
||||
static unsigned int ww, wh;
|
||||
|
||||
static Display *d;
|
||||
static Window root, cur;
|
||||
static Window root;
|
||||
static XButtonEvent mouse;
|
||||
|
||||
static void (*events[LASTEvent])(XEvent *e) = {
|
||||
@ -67,7 +67,6 @@ static void (*events[LASTEvent])(XEvent *e) = {
|
||||
#include "config.h"
|
||||
|
||||
#define win (client *t=0, *c=list; c && t!=list->prev; t=c, c=c->next)
|
||||
#define win_focus(W) XSetInputFocus(d, W, RevertToParent, CurrentTime)
|
||||
#define ws_save(W) ws_list[W] = list
|
||||
#define ws_sel(W) list = ws_list[ws = W]
|
||||
|
||||
@ -75,15 +74,17 @@ static void (*events[LASTEvent])(XEvent *e) = {
|
||||
XGetGeometry(d, W, &(Window){0}, gx, gy, gw, gh, \
|
||||
&(unsigned int){0}, &(unsigned int){0})
|
||||
|
||||
Window win_current() {
|
||||
XGetInputFocus(d, &cur, &(int){1});
|
||||
return cur;
|
||||
void win_focus(Window w) {
|
||||
for win if (c->w == w) {
|
||||
XSetInputFocus(d, w, RevertToParent, CurrentTime);
|
||||
cur = c;
|
||||
}
|
||||
}
|
||||
|
||||
void notify_destroy(XEvent *e) {
|
||||
win_del(e->xdestroywindow.window);
|
||||
|
||||
if (list) win_focus(win_current() == root ? list->w : cur);
|
||||
if (list) win_focus(list->w);
|
||||
}
|
||||
|
||||
void notify_enter(XEvent *e) {
|
||||
@ -167,55 +168,50 @@ void win_del(Window w) {
|
||||
}
|
||||
|
||||
void win_kill() {
|
||||
if (win_current() ^ root) XKillClient(d, cur);
|
||||
if (cur) XKillClient(d, cur->w);
|
||||
}
|
||||
|
||||
void win_center(const Arg arg) {
|
||||
Window w = arg.w ? arg.w : win_current();
|
||||
void win_center() {
|
||||
if (!cur) return;
|
||||
|
||||
win_size(w, &(int){0}, &(int){0}, &ww, &wh);
|
||||
win_size(cur->w, &(int){0}, &(int){0}, &ww, &wh);
|
||||
|
||||
XMoveWindow(d, w, (sw - ww) / 2, (sh - wh) / 2);
|
||||
XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2);
|
||||
}
|
||||
|
||||
void win_fs() {
|
||||
win_current();
|
||||
if (!cur) return;
|
||||
|
||||
for win if (c->w == cur) {
|
||||
if ((c->f = c->f == 0 ? 1 : 0)) {
|
||||
win_size(cur, &c->wx, &c->wy, &c->ww, &c->wh);
|
||||
XMoveResizeWindow(d, cur, 0, 0, sw, sh);
|
||||
if ((cur->f = cur->f == 0 ? 1 : 0)) {
|
||||
win_size(cur->w, &cur->wx, &cur->wy, &cur->ww, &cur->wh);
|
||||
XMoveResizeWindow(d, cur->w, 0, 0, sw, sh);
|
||||
|
||||
} else
|
||||
XMoveResizeWindow(d, cur, c->wx, c->wy, c->ww, c->wh);
|
||||
}
|
||||
} else
|
||||
XMoveResizeWindow(d, cur->w, cur->wx, cur->wy, cur->ww, cur->wh);
|
||||
}
|
||||
|
||||
void win_to_ws(const Arg arg) {
|
||||
int tmp = ws;
|
||||
win_current();
|
||||
|
||||
if (arg.i == tmp) return;
|
||||
|
||||
ws_sel(arg.i);
|
||||
win_add(cur);
|
||||
win_add(cur->w);
|
||||
ws_save(arg.i);
|
||||
|
||||
ws_sel(tmp);
|
||||
win_del(cur);
|
||||
XUnmapWindow(d, cur);
|
||||
win_del(cur->w);
|
||||
XUnmapWindow(d, cur->w);
|
||||
ws_save(tmp);
|
||||
|
||||
if (list) win_focus(list->w);
|
||||
}
|
||||
|
||||
void win_next() {
|
||||
win_current();
|
||||
if (!cur) return;
|
||||
|
||||
for win if (c->w == cur) {
|
||||
win_focus(c->next->w);
|
||||
XRaiseWindow(d, c->next->w);
|
||||
}
|
||||
XRaiseWindow(d, cur->next->w);
|
||||
win_focus(cur->next->w);
|
||||
}
|
||||
|
||||
void ws_go(const Arg arg) {
|
||||
@ -256,11 +252,10 @@ void map_request(XEvent *e) {
|
||||
XSelectInput(d, w, StructureNotifyMask|EnterWindowMask);
|
||||
win_size(w, &wx, &wy, &ww, &wh);
|
||||
|
||||
if (wx == 0 && wy == 0) win_center((Arg){.i = w});
|
||||
|
||||
XMapWindow(d, w);
|
||||
win_focus(w);
|
||||
win_add(w);
|
||||
win_focus(w);
|
||||
if (wx == 0 && wy == 0) win_center();
|
||||
XMapWindow(d, w);
|
||||
}
|
||||
|
||||
void run(const Arg arg) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user