mirror of
https://github.com/dylanaraps/sowm.git
synced 2025-07-31 20:21:57 -07:00
sowm: move two overly simple functions to macros.
This commit is contained in:
72
sowm.c
72
sowm.c
@@ -7,19 +7,6 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
/*
|
|
||||||
This iterates over the current desktop's
|
|
||||||
window list and is inserted where needed.
|
|
||||||
*/
|
|
||||||
#define WIN (c=list;c;c=c->next)
|
|
||||||
|
|
||||||
/*
|
|
||||||
This sets focus to the given window. It
|
|
||||||
could very well be a function but I feel
|
|
||||||
it belongs here.
|
|
||||||
*/
|
|
||||||
#define FOC(W) XSetInputFocus(d, W, RevertToParent, CurrentTime);
|
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
const char** com;
|
const char** com;
|
||||||
const int i;
|
const int i;
|
||||||
@@ -62,8 +49,6 @@ static void win_kill();
|
|||||||
static void win_next();
|
static void win_next();
|
||||||
static void win_to_ws(const Arg arg);
|
static void win_to_ws(const Arg arg);
|
||||||
static void ws_go(const Arg arg);
|
static void ws_go(const Arg arg);
|
||||||
static void ws_save(int i);
|
|
||||||
static void ws_sel(int i);
|
|
||||||
|
|
||||||
static client *list = {0};
|
static client *list = {0};
|
||||||
static desktop ws_list[10];
|
static desktop ws_list[10];
|
||||||
@@ -74,8 +59,6 @@ static Window root, cur;
|
|||||||
static XButtonEvent mouse;
|
static XButtonEvent mouse;
|
||||||
static XWindowAttributes attr;
|
static XWindowAttributes attr;
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The list of events to subscribe to and the paired functions
|
The list of events to subscribe to and the paired functions
|
||||||
to call on an event.
|
to call on an event.
|
||||||
@@ -91,6 +74,20 @@ static void (*events[LASTEvent])(XEvent *e) = {
|
|||||||
[MotionNotify] = notify_motion
|
[MotionNotify] = notify_motion
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
// Iterate over the current desktop's window list.
|
||||||
|
#define win (c=list;c;c=c->next)
|
||||||
|
|
||||||
|
// Focus the given window.
|
||||||
|
#define win_focus(W) XSetInputFocus(d, W, RevertToParent, CurrentTime);
|
||||||
|
|
||||||
|
// Save the current desktop's window list.
|
||||||
|
#define ws_save(i) ws_list[i].list = list;
|
||||||
|
|
||||||
|
// Select the current desktop's window list.
|
||||||
|
#define ws_sel(i) list = ws_list[i].list, ws = i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
'sowm' doesn't keep track of the currently focused window
|
'sowm' doesn't keep track of the currently focused window
|
||||||
and instead grabs the window under the cursor when needed.
|
and instead grabs the window under the cursor when needed.
|
||||||
@@ -126,7 +123,7 @@ Window win_current() {
|
|||||||
void notify_destroy(XEvent *e) {
|
void notify_destroy(XEvent *e) {
|
||||||
win_del(e->xdestroywindow.window);
|
win_del(e->xdestroywindow.window);
|
||||||
|
|
||||||
if (list) FOC(win_current() == root ? list->w : cur);
|
if (list) win_focus(win_current() == root ? list->w : cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -146,7 +143,7 @@ void notify_destroy(XEvent *e) {
|
|||||||
void notify_enter(XEvent *e) {
|
void notify_enter(XEvent *e) {
|
||||||
while(XCheckTypedEvent(d, EnterNotify, e));
|
while(XCheckTypedEvent(d, EnterNotify, e));
|
||||||
|
|
||||||
if (e->xcrossing.window != root) FOC(e->xcrossing.window)
|
if (e->xcrossing.window != root) win_focus(e->xcrossing.window)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -242,7 +239,7 @@ void button_press(XEvent *e) {
|
|||||||
void button_release() {
|
void button_release() {
|
||||||
client *c;
|
client *c;
|
||||||
|
|
||||||
for WIN if (c->w == mouse.subwindow) c->f = 0;
|
for win if (c->w == mouse.subwindow) c->f = 0;
|
||||||
|
|
||||||
mouse.subwindow = None;
|
mouse.subwindow = None;
|
||||||
}
|
}
|
||||||
@@ -287,7 +284,7 @@ void win_add(Window w) {
|
|||||||
void win_del(Window w) {
|
void win_del(Window w) {
|
||||||
client *c;
|
client *c;
|
||||||
|
|
||||||
for WIN if (c->w == w) {
|
for win if (c->w == w) {
|
||||||
if (!c->prev && !c->next) {
|
if (!c->prev && !c->next) {
|
||||||
free(list);
|
free(list);
|
||||||
list = 0;
|
list = 0;
|
||||||
@@ -362,7 +359,7 @@ void win_fs() {
|
|||||||
|
|
||||||
win_current();
|
win_current();
|
||||||
|
|
||||||
for WIN if (c->w == cur) {
|
for win if (c->w == cur) {
|
||||||
if ((c->f = c->f == 0 ? 1 : 0)) {
|
if ((c->f = c->f == 0 ? 1 : 0)) {
|
||||||
XGetWindowAttributes(d, cur, &c->a);
|
XGetWindowAttributes(d, cur, &c->a);
|
||||||
XMoveResizeWindow(d, cur, 0, 0, sw, sh);
|
XMoveResizeWindow(d, cur, 0, 0, sw, sh);
|
||||||
@@ -399,7 +396,7 @@ void win_to_ws(const Arg arg) {
|
|||||||
XUnmapWindow(d, cur);
|
XUnmapWindow(d, cur);
|
||||||
ws_save(tmp);
|
ws_save(tmp);
|
||||||
|
|
||||||
if (list) FOC(list->w);
|
if (list) win_focus(list->w);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -417,11 +414,11 @@ void win_next() {
|
|||||||
client *c;
|
client *c;
|
||||||
|
|
||||||
if (list) {
|
if (list) {
|
||||||
for WIN if (c->w == cur) break;
|
for win if (c->w == cur) break;
|
||||||
|
|
||||||
c = c->next ? c->next : list;
|
c = c->next ? c->next : list;
|
||||||
|
|
||||||
FOC(c->w);
|
win_focus(c->w);
|
||||||
XRaiseWindow(d, c->w);
|
XRaiseWindow(d, c->w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -445,32 +442,15 @@ void ws_go(const Arg arg) {
|
|||||||
ws_save(ws);
|
ws_save(ws);
|
||||||
ws_sel(arg.i);
|
ws_sel(arg.i);
|
||||||
|
|
||||||
if (list) for WIN XMapWindow(d, c->w);
|
if (list) for win XMapWindow(d, c->w);
|
||||||
|
|
||||||
ws_sel(tmp);
|
ws_sel(tmp);
|
||||||
|
|
||||||
if (list) for WIN XUnmapWindow(d, c->w);
|
if (list) for win XUnmapWindow(d, c->w);
|
||||||
|
|
||||||
ws_sel(arg.i);
|
ws_sel(arg.i);
|
||||||
|
|
||||||
if (list) FOC(list->w);
|
if (list) win_focus(list->w);
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
This function saves the current desktop's window list.
|
|
||||||
Simple, nothing to see here.
|
|
||||||
*/
|
|
||||||
void ws_save(int i) {
|
|
||||||
ws_list[i].list = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
This function restores a saved desktop's window list.
|
|
||||||
Simple, nothing to see here.
|
|
||||||
*/
|
|
||||||
void ws_sel(int i) {
|
|
||||||
list = ws_list[i].list;
|
|
||||||
ws = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -513,7 +493,7 @@ void map_request(XEvent *e) {
|
|||||||
|
|
||||||
win_center((Arg){.i = w});
|
win_center((Arg){.i = w});
|
||||||
XMapWindow(d, w);
|
XMapWindow(d, w);
|
||||||
FOC(w);
|
win_focus(w);
|
||||||
win_add(w);
|
win_add(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user