mirror of
https://github.com/dylanaraps/sowm.git
synced 2025-08-22 23:43:52 -07:00
sowm: revert oops
This commit is contained in:
94
sowm.c
94
sowm.c
@@ -37,7 +37,7 @@ 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_del(client *c);
|
||||
static void win_del(Window w);
|
||||
static void win_fs();
|
||||
static void win_kill();
|
||||
static void win_next();
|
||||
@@ -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}, *cur = {0};
|
||||
static client *list = {0}, *ws_list[10] = {0};
|
||||
static int ws = 1, sw, sh, wx, wy;
|
||||
static unsigned int ww, wh;
|
||||
|
||||
static Display *d;
|
||||
static Window root;
|
||||
static Window root, cur;
|
||||
static XButtonEvent mouse;
|
||||
|
||||
static void (*events[LASTEvent])(XEvent *e) = {
|
||||
@@ -67,6 +67,7 @@ static void (*events[LASTEvent])(XEvent *e) = {
|
||||
#include "config.h"
|
||||
|
||||
#define win (client *c=list;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]
|
||||
|
||||
@@ -74,16 +75,15 @@ static void (*events[LASTEvent])(XEvent *e) = {
|
||||
XGetGeometry(d, W, &(Window){0}, gx, gy, gw, gh, \
|
||||
&(unsigned int){0}, &(unsigned int){0})
|
||||
|
||||
void win_focus(Window w) {
|
||||
XSetInputFocus(d, w, RevertToParent, CurrentTime);
|
||||
|
||||
for win if (c->w == w) cur = c;
|
||||
Window win_current() {
|
||||
XGetInputFocus(d, &cur, &(int){1});
|
||||
return cur;
|
||||
}
|
||||
|
||||
void notify_destroy(XEvent *e) {
|
||||
for win if (c->w == e->xdestroywindow.window) win_del(c);
|
||||
win_del(e->xdestroywindow.window);
|
||||
|
||||
if (list) win_focus(list->w);
|
||||
if (list) win_focus(win_current() == root ? list->w : cur);
|
||||
}
|
||||
|
||||
void notify_enter(XEvent *e) {
|
||||
@@ -152,28 +152,39 @@ void win_add(Window w) {
|
||||
ws_save(ws);
|
||||
}
|
||||
|
||||
void win_del(client *c) {
|
||||
if (c == list) {
|
||||
list = list->next ? list->next : 0;
|
||||
goto del;
|
||||
void win_del(Window w) {
|
||||
for win if (c->w == w) {
|
||||
if (!c->prev && !c->next) {
|
||||
free(list);
|
||||
list = 0;
|
||||
ws_save(ws);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!c->prev) {
|
||||
list = c->next;
|
||||
c->next->prev = 0;
|
||||
|
||||
} else if (!c->next) {
|
||||
c->prev->next = 0;
|
||||
|
||||
} else {
|
||||
c->prev->next = c->next;
|
||||
c->next->prev = c->prev;
|
||||
}
|
||||
|
||||
free(c);
|
||||
ws_save(ws);
|
||||
return;
|
||||
}
|
||||
|
||||
if (c->prev) c->prev->next = c->next;
|
||||
if (c->next) c->next->prev = c->prev;
|
||||
|
||||
del:
|
||||
free(c);
|
||||
ws_save(ws);
|
||||
}
|
||||
|
||||
void win_kill() {
|
||||
if (cur) XKillClient(d, cur->w);
|
||||
if (win_current() ^ root) XKillClient(d, cur);
|
||||
}
|
||||
|
||||
void win_center(const Arg arg) {
|
||||
if (!cur) return;
|
||||
|
||||
Window w = arg.w ? arg.w : cur->w;
|
||||
Window w = arg.w ? arg.w : win_current();
|
||||
|
||||
win_size(w, &(int){0}, &(int){0}, &ww, &wh);
|
||||
|
||||
@@ -181,40 +192,46 @@ void win_center(const Arg arg) {
|
||||
}
|
||||
|
||||
void win_fs() {
|
||||
if (!cur) return;
|
||||
win_current();
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
} else
|
||||
XMoveResizeWindow(d, cur->w, cur->wx, cur->wy, cur->ww, cur->wh);
|
||||
} else
|
||||
XMoveResizeWindow(d, cur, c->wx, c->wy, c->ww, c->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->w);
|
||||
win_add(cur);
|
||||
ws_save(arg.i);
|
||||
|
||||
ws_sel(tmp);
|
||||
win_del(cur);
|
||||
XUnmapWindow(d, cur->w);
|
||||
XUnmapWindow(d, cur);
|
||||
ws_save(tmp);
|
||||
|
||||
if (list) win_focus(list->w);
|
||||
}
|
||||
|
||||
void win_next() {
|
||||
if (!list) return;
|
||||
win_current();
|
||||
|
||||
client *c = cur->next ? cur->next : list;
|
||||
for win if (c->w == cur) {
|
||||
c = c->next ? c->next : list;
|
||||
|
||||
win_focus(c->w);
|
||||
XRaiseWindow(d, c->w);
|
||||
win_focus(c->w);
|
||||
XRaiseWindow(d, c->w);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ws_go(const Arg arg) {
|
||||
@@ -253,14 +270,13 @@ void map_request(XEvent *e) {
|
||||
Window w = e->xmaprequest.window;
|
||||
|
||||
XSelectInput(d, w, StructureNotifyMask|EnterWindowMask);
|
||||
|
||||
win_size(w, &wx, &wy, &ww, &wh);
|
||||
win_add(w);
|
||||
win_focus(w);
|
||||
|
||||
if (wx == 0 && wy == 0) win_center((Arg){.i = w});
|
||||
|
||||
XMapWindow(d, w);
|
||||
win_focus(w);
|
||||
win_add(w);
|
||||
}
|
||||
|
||||
void run(const Arg arg) {
|
||||
|
Reference in New Issue
Block a user