#include "conf.h"
/* Types */
-typedef enum { number, string } type_t;
+typedef enum { NUMBER, STRING } type_t;
typedef struct {
type_t type;
if ((entry = conf_get(key))) {
tdelete(entry, &conf, conf_cmp);
free(entry->key);
- if (entry->type == string)
+ if (entry->type == STRING)
free(entry->str);
free(entry);
}
entry = new0(entry_t);
entry->key = strdup(key);
if (str) {
- entry->type = string;
+ entry->type = STRING;
entry->str = strdup(str);
printf("set_str: %s = %s\n", key, str);
} else {
- entry->type = number;
+ entry->type = NUMBER;
entry->num = num;
printf("set_num: %s = %d\n", key, num);
}
int conf_get_int(const char *key, int def)
{
entry_t *entry = conf_get(key);
- return entry && entry->type == number
+ return entry && entry->type == NUMBER
? entry->num : def;
}
const char *conf_get_str(const char *key, const char *def)
{
entry_t *entry = conf_get(key);
- return entry && entry->type == string
+ return entry && entry->type == STRING
? entry->str : def;
}
#include "wm.h"
/* Configuration */
-static int NO_CAPTURE = 0;
-static int STACK = 25;
+static int no_capture = 0;
+static int stack = 25;
/* Internal structures */
struct win_sys {
};
typedef struct {
- Key_t key;
- int vk;
-} keymap_t;
+ event_t ev;
+ int vk;
+} event_map_t;
/* Global data */
static int shellhookid;
static list_t *screens;
/* Conversion functions */
-static keymap_t key2vk[] = {
- {key_mouse1 , VK_LBUTTON },
- {key_mouse2 , VK_MBUTTON },
- {key_mouse3 , VK_RBUTTON },
- {key_left , VK_LEFT },
- {key_right , VK_RIGHT },
- {key_up , VK_UP },
- {key_down , VK_DOWN },
- {key_home , VK_HOME },
- {key_end , VK_END },
- {key_pageup , VK_PRIOR },
- {key_pagedown, VK_NEXT },
- {key_f1 , VK_F1 },
- {key_f2 , VK_F2 },
- {key_f3 , VK_F3 },
- {key_f4 , VK_F4 },
- {key_f5 , VK_F5 },
- {key_f6 , VK_F6 },
- {key_f7 , VK_F7 },
- {key_f8 , VK_F8 },
- {key_f9 , VK_F9 },
- {key_f10 , VK_F10 },
- {key_f11 , VK_F11 },
- {key_f12 , VK_F12 },
- {key_shift , VK_SHIFT },
- {key_shift , VK_LSHIFT },
- {key_shift , VK_RSHIFT },
- {key_ctrl , VK_CONTROL },
- {key_ctrl , VK_LCONTROL},
- {key_ctrl , VK_RCONTROL},
- {key_alt , VK_MENU },
- {key_alt , VK_LMENU },
- {key_alt , VK_RMENU },
- {key_win , VK_LWIN },
- {key_win , VK_RWIN },
+static event_map_t ev2vk[] = {
+ {EV_MOUSE1 , VK_LBUTTON },
+ {EV_MOUSE2 , VK_MBUTTON },
+ {EV_MOUSE3 , VK_RBUTTON },
+ {EV_LEFT , VK_LEFT },
+ {EV_RIGHT , VK_RIGHT },
+ {EV_UP , VK_UP },
+ {EV_DOWN , VK_DOWN },
+ {EV_HOME , VK_HOME },
+ {EV_END , VK_END },
+ {EV_PAGEUP , VK_PRIOR },
+ {EV_PAGEDOWN, VK_NEXT },
+ {EV_F1 , VK_F1 },
+ {EV_F2 , VK_F2 },
+ {EV_F3 , VK_F3 },
+ {EV_F4 , VK_F4 },
+ {EV_F5 , VK_F5 },
+ {EV_F6 , VK_F6 },
+ {EV_F7 , VK_F7 },
+ {EV_F8 , VK_F8 },
+ {EV_F9 , VK_F9 },
+ {EV_F10 , VK_F10 },
+ {EV_F11 , VK_F11 },
+ {EV_F12 , VK_F12 },
+ {EV_SHIFT , VK_SHIFT },
+ {EV_SHIFT , VK_LSHIFT },
+ {EV_SHIFT , VK_RSHIFT },
+ {EV_CTRL , VK_CONTROL },
+ {EV_CTRL , VK_LCONTROL},
+ {EV_CTRL , VK_RCONTROL},
+ {EV_ALT , VK_MENU },
+ {EV_ALT , VK_LMENU },
+ {EV_ALT , VK_RMENU },
+ {EV_WIN , VK_LWIN },
+ {EV_WIN , VK_RWIN },
};
/* - Keycodes */
-static Key_t w2key(UINT vk)
+static event_t w2ev(UINT vk)
{
- keymap_t *km = map_getr(key2vk,vk);
- return km ? km->key : tolower(vk);
+ event_map_t *em = map_getr(ev2vk,vk);
+ return em ? em->ev : tolower(vk);
}
-static UINT key2w(Key_t key)
+static UINT ev2w(event_t ev)
{
- keymap_t *km = map_get(key2vk,key);
- return km ? km->vk : toupper(key);
+ event_map_t *em = map_get(ev2vk,ev);
+ return em ? em->vk : toupper(ev);
}
static mod_t getmod(void)
LRESULT CALLBACK KbdProc(int msg, WPARAM wParam, LPARAM lParam)
{
KBDLLHOOKSTRUCT *st = (KBDLLHOOKSTRUCT *)lParam;
- Key_t key = w2key(st->vkCode);
+ event_t ev = w2ev(st->vkCode);
mod_t mod = getmod();
mod.up = !!(st->flags & 0x80);
printf("KbdProc: %d,%x,%lx - %lx,%lx,%lx - %x,%x\n",
msg, wParam, lParam,
st->vkCode, st->scanCode, st->flags,
- key, mod2int(mod));
- return wm_handle_key(win_focused() ?: root, key, mod, getptr())
+ ev, mod2int(mod));
+ return wm_handle_event(win_focused() ?: root, ev, mod, getptr())
|| CallNextHookEx(0, msg, wParam, lParam);
}
LRESULT CALLBACK MllProc(int msg, WPARAM wParam, LPARAM lParam)
{
- Key_t key = key_none;
+ event_t ev = EV_NONE;
mod_t mod = getmod();
win_t *win = win_cursor();
/* Update modifiers */
switch (wParam) {
- case WM_LBUTTONDOWN: mod.up = 0; key = key_mouse1; break;
- case WM_LBUTTONUP: mod.up = 1; key = key_mouse1; break;
- case WM_RBUTTONDOWN: mod.up = 0; key = key_mouse3; break;
- case WM_RBUTTONUP: mod.up = 1; key = key_mouse3; break;
+ case WM_LBUTTONDOWN: mod.up = 0; ev = EV_MOUSE1; break;
+ case WM_LBUTTONUP: mod.up = 1; ev = EV_MOUSE1; break;
+ case WM_RBUTTONDOWN: mod.up = 0; ev = EV_MOUSE3; break;
+ case WM_RBUTTONUP: mod.up = 1; ev = EV_MOUSE3; break;
}
/* Check for focus-in/focus-out */
static win_t *old = NULL;
if (win && win != old) {
- wm_handle_key(old, key_leave, mod, getptr());
- wm_handle_key(win, key_enter, mod, getptr());
+ wm_handle_event(old, EV_LEAVE, mod, getptr());
+ wm_handle_event(win, EV_ENTER, mod, getptr());
}
old = win;
/* Send mouse movement event */
if (wParam == WM_MOUSEMOVE)
return wm_handle_ptr(win_cursor(), getptr());
- else if (key != key_none)
- return wm_handle_key(win_cursor(), key, mod, getptr());
+ else if (ev != EV_NONE)
+ return wm_handle_event(win_cursor(), ev, mod, getptr());
else
return CallNextHookEx(0, msg, wParam, lParam);
}
printf("ShlProc: %p - %s\n", hwnd, msg == HSHELL_WINDOWREPLACED ?
"window replaced" : "window destroyed");
if ((win = win_find(hwnd,0)) &&
- (win->state == st_show ||
- win->state == st_shade)) {
+ (win->state == ST_SHOW ||
+ win->state == ST_SHADE)) {
wm_remove(win);
win_remove(win);
}
printf("ShlProc: %p - window activated\n", hwnd);
// Fake button-click (causes crazy switching)
//if ((win = win_find(hwnd,0)))
- // wm_handle_key(win, key_mouse1, MOD(), getptr());
+ // wm_handle_event(win, EV_MOUSE1, MOD(), getptr());
return 0;
default:
printf("ShlProc: %p - unknown msg, %d\n", hwnd, msg);
char *str;
int cmd;
} map[] = {
- [st_show ] {"show" , SW_SHOW },
- [st_full ] {"full" , SW_MAXIMIZE},
- [st_shade] {"shade", SW_SHOW },
- [st_icon ] {"icon" , SW_MINIMIZE},
- [st_hide ] {"hide" , SW_HIDE },
+ [ST_SHOW ] {"show" , SW_SHOW },
+ [ST_FULL ] {"full" , SW_MAXIMIZE},
+ [ST_SHADE] {"shade", SW_SHOW },
+ [ST_ICON ] {"icon" , SW_MINIMIZE},
+ [ST_HIDE ] {"hide" , SW_HIDE },
};
- if (win->state != state && win->state == st_shade)
+ if (win->state != state && win->state == ST_SHADE)
SetWindowRgn(win->sys->hwnd, NULL, TRUE);
win->state = state;
printf("sys_show: %s\n", map[state].str);
ShowWindow(win->sys->hwnd, map[state].cmd);
- if (state == st_shade)
- SetWindowRgn(win->sys->hwnd, CreateRectRgn(0,0,win->w,STACK), TRUE);
+ if (state == ST_SHADE)
+ SetWindowRgn(win->sys->hwnd, CreateRectRgn(0,0,win->w,stack), TRUE);
}
-void sys_watch(win_t *win, Key_t key, mod_t mod)
+void sys_watch(win_t *win, event_t ev, mod_t mod)
{
- (void)key2w; // TODO
+ (void)ev2w; // TODO
//printf("sys_watch: %p\n", win);
}
-void sys_unwatch(win_t *win, Key_t key, mod_t mod)
+void sys_unwatch(win_t *win, event_t ev, mod_t mod)
{
- (void)key2w; // TODO
+ (void)ev2w; // TODO
//printf("sys_unwatch: %p\n", win);
}
HWND hwnd = NULL;
/* Load configuration */
- NO_CAPTURE = conf_get_int("main.no-capture", NO_CAPTURE);
- STACK = conf_get_int("main.stack", STACK);
+ no_capture = conf_get_int("main.no-capture", no_capture);
+ stack = conf_get_int("main.stack", stack);
/* Setup window class */
WNDCLASSEX wc = {
void sys_run(win_t *root)
{
MSG msg = {};
- if (!NO_CAPTURE)
+ if (!no_capture)
EnumWindows(LoopProc, 0);
while (GetMessage(&msg, NULL, 0, 0) > 0 &&
msg.message != WM_QUIT) {
#include "wm.h"
/* Configuration */
-static int BORDER = 2;
-static int NO_CAPTURE = 0;
+static int border = 2;
+static int no_capture = 0;
/* Internal structures */
struct win_sys {
};
typedef struct {
- Key_t key;
- int sym;
-} keymap_t;
+ event_t ev;
+ int sym;
+} event_map_t;
typedef enum {
- wm_proto, wm_focus, net_strut, natoms
+ WM_PROTO, WM_FOCUS, NET_STRUT, NATOMS
} atom_t;
typedef enum {
- clr_focus, clr_unfocus, clr_urgent, ncolors
+ CLR_FOCUS, CLR_UNFOCUS, CLR_URGENT, NCOLORS
} color_t;
/* Global data */
static int running;
static void *cache;
-static Atom atoms[natoms];
+static Atom atoms[NATOMS];
static int (*xerrorxlib)(Display *, XErrorEvent *);
-static unsigned long colors[ncolors];
+static unsigned long colors[NCOLORS];
static list_t *screens;
/* Conversion functions */
-static keymap_t key2sym[] = {
- {key_left , XK_Left },
- {key_right , XK_Right},
- {key_up , XK_Up },
- {key_down , XK_Down },
- {key_home , XK_Home },
- {key_end , XK_End },
- {key_pageup , XK_Prior},
- {key_pagedown, XK_Next },
- {key_f1 , XK_F1 },
- {key_f2 , XK_F2 },
- {key_f3 , XK_F3 },
- {key_f4 , XK_F4 },
- {key_f5 , XK_F5 },
- {key_f6 , XK_F6 },
- {key_f7 , XK_F7 },
- {key_f8 , XK_F8 },
- {key_f9 , XK_F9 },
- {key_f10 , XK_F10 },
- {key_f11 , XK_F11 },
- {key_f12 , XK_F12 },
+static event_map_t ev2sym[] = {
+ {EV_LEFT , XK_Left },
+ {EV_RIGHT , XK_Right},
+ {EV_UP , XK_Up },
+ {EV_DOWN , XK_Down },
+ {EV_HOME , XK_Home },
+ {EV_END , XK_End },
+ {EV_PAGEUP , XK_Prior},
+ {EV_PAGEDOWN, XK_Next },
+ {EV_F1 , XK_F1 },
+ {EV_F2 , XK_F2 },
+ {EV_F3 , XK_F3 },
+ {EV_F4 , XK_F4 },
+ {EV_F5 , XK_F5 },
+ {EV_F6 , XK_F6 },
+ {EV_F7 , XK_F7 },
+ {EV_F8 , XK_F8 },
+ {EV_F9 , XK_F9 },
+ {EV_F10 , XK_F10 },
+ {EV_F11 , XK_F11 },
+ {EV_F12 , XK_F12 },
};
/* - Modifiers */
}
/* - Keycodes */
-static Key_t x2key(KeySym sym)
+static event_t xk2ev(KeySym sym)
{
- keymap_t *km = map_getr(key2sym,sym);
- return km ? km->key : sym;
+ event_map_t *em = map_getr(ev2sym,sym);
+ return em ? em->ev : sym;
}
-static KeySym key2x(Key_t key)
+static KeySym ev2xk(event_t ev)
{
- keymap_t *km = map_get(key2sym,key);
- return km ? km->sym : key;
+ event_map_t *em = map_get(ev2sym,ev);
+ return em ? em->sym : ev;
}
-static Key_t x2btn(int btn)
+static event_t xb2ev(int btn)
{
- return btn + key_mouse0;
+ return btn + EV_MOUSE0;
}
-static int btn2x(Key_t key)
+static int ev2xb(event_t ev)
{
- return key - key_mouse0;
+ return ev - EV_MOUSE0;
}
/* - Pointers */
-static ptr_t x2ptr(XEvent *_ev)
+static ptr_t x2ptr(XEvent *xe)
{
- XKeyEvent *ev = &_ev->xkey;
- return (ptr_t){ev->x, ev->y, ev->x_root, ev->y_root};
+ XKeyEvent *xke = &xe->xkey;
+ return (ptr_t){xke->x, xke->y, xke->x_root, xke->y_root};
}
-static Window getfocus(win_t *root, XEvent *event)
+static Window getfocus(win_t *root, XEvent *xe)
{
int revert;
Window focus = PointerRoot;
- if (event->type == KeyPress || event->type == KeyRelease)
+ if (xe->type == KeyPress || xe->type == KeyRelease)
XGetInputFocus(root->sys->dpy, &focus, &revert);
if (focus == PointerRoot)
- focus = event->xkey.subwindow;
+ focus = xe->xkey.subwindow;
if (focus == None)
- focus = event->xkey.window;
+ focus = xe->xkey.window;
return focus;
}
unsigned long ret_items, bytes_left;
unsigned char *xdata;
int status = XGetWindowProperty(win->sys->dpy, win->sys->xid,
- atoms[net_strut], 0L, 4L, False, XA_CARDINAL,
+ atoms[NET_STRUT], 0L, 4L, False, XA_CARDINAL,
&ret_type, &ret_size, &ret_items, &bytes_left, &xdata);
if (status != Success || ret_size != 32 || ret_items != 4)
return 0;
}
/* Callbacks */
-static void process_event(int type, XEvent *ev, win_t *root)
+static void process_event(int type, XEvent *xe, win_t *root)
{
Display *dpy = root->sys->dpy;
win_t *win = NULL;
if (type == KeyPress || type == KeyRelease ||
type == ButtonPress || type == ButtonRelease ||
type == MotionNotify) {
- Window xid = getfocus(root, ev);
+ Window xid = getfocus(root, xe);
if (!(win = win_find(dpy,xid,0)))
return;
- ptr = x2ptr(ev);
- mod = x2mod(ev->xkey.state, type==KeyRelease||type==ButtonRelease);
+ ptr = x2ptr(xe);
+ mod = x2mod(xe->xkey.state, type==KeyRelease||type==ButtonRelease);
}
/* Split based on event */
if (type == KeyPress) {
- while (XCheckTypedEvent(dpy, KeyPress, ev));
- KeySym sym = XKeycodeToKeysym(dpy, ev->xkey.keycode, 0);
- printf("got key %c %hhx\n", x2key(sym), mod2int(mod));
- wm_handle_key(win, x2key(sym), mod, ptr);
+ while (XCheckTypedEvent(dpy, KeyPress, xe));
+ KeySym sym = XKeycodeToKeysym(dpy, xe->xkey.keycode, 0);
+ printf("got xe %c %hhx\n", xk2ev(sym), mod2int(mod));
+ wm_handle_event(win, xk2ev(sym), mod, ptr);
}
else if (type == KeyRelease) {
//printf("release: %d\n", type);
}
else if (type == ButtonPress) {
- if (wm_handle_key(win, x2btn(ev->xbutton.button), mod, ptr))
- XGrabPointer(dpy, ev->xbutton.root, True, PointerMotionMask|ButtonReleaseMask,
+ if (wm_handle_event(win, xb2ev(xe->xbutton.button), mod, ptr))
+ XGrabPointer(dpy, xe->xbutton.root, True, PointerMotionMask|ButtonReleaseMask,
GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
else {
printf("resending event\n");
- XSendEvent(win->sys->dpy, ev->xbutton.window, True, NoEventMask, ev);
- XSendEvent(win->sys->dpy, ev->xbutton.window, False, NoEventMask, ev);
- XSendEvent(win->sys->dpy, ev->xbutton.root, True, NoEventMask, ev);
- XSendEvent(win->sys->dpy, ev->xbutton.root, False, NoEventMask, ev);
- XSendEvent(win->sys->dpy, ev->xbutton.subwindow, True, NoEventMask, ev);
- XSendEvent(win->sys->dpy, ev->xbutton.subwindow, False, NoEventMask, ev);
+ XSendEvent(win->sys->dpy, xe->xbutton.window, True, NoEventMask, xe);
+ XSendEvent(win->sys->dpy, xe->xbutton.window, False, NoEventMask, xe);
+ XSendEvent(win->sys->dpy, xe->xbutton.root, True, NoEventMask, xe);
+ XSendEvent(win->sys->dpy, xe->xbutton.root, False, NoEventMask, xe);
+ XSendEvent(win->sys->dpy, xe->xbutton.subwindow, True, NoEventMask, xe);
+ XSendEvent(win->sys->dpy, xe->xbutton.subwindow, False, NoEventMask, xe);
}
}
else if (type == ButtonRelease) {
XUngrabPointer(dpy, CurrentTime);
- wm_handle_key(win, x2btn(ev->xbutton.button), mod, ptr);
+ wm_handle_event(win, xb2ev(xe->xbutton.button), mod, ptr);
}
else if (type == MotionNotify) {
- while (XCheckTypedEvent(dpy, MotionNotify, ev));
+ while (XCheckTypedEvent(dpy, MotionNotify, xe));
wm_handle_ptr(win, ptr);
}
else if (type == EnterNotify || type == LeaveNotify) {
printf("enter: %d\n", type);
- key_t key = EnterNotify ? key_enter : key_leave;
- if ((win = win_find(dpy,ev->xcrossing.window,0)))
- wm_handle_key(win, key, MOD(), PTR());
+ event_t ev = EnterNotify ? EV_ENTER : EV_LEAVE;
+ if ((win = win_find(dpy,xe->xcrossing.window,0)))
+ wm_handle_event(win, ev, MOD(), PTR());
}
else if (type == FocusIn || type == FocusOut) {
//printf("focus: %d\n", type);
- key_t key = FocusIn ? key_focus : key_unfocus;
- if ((win = win_find(dpy,ev->xfocus.window,0)))
- wm_handle_key(win, key, MOD(), PTR());
+ event_t ev = FocusIn ? EV_FOCUS : EV_UNFOCUS;
+ if ((win = win_find(dpy,xe->xfocus.window,0)))
+ wm_handle_event(win, ev, MOD(), PTR());
}
else if (type == ConfigureNotify) {
printf("configure: %d\n", type);
printf("map: %d\n", type);
}
else if (type == UnmapNotify) {
- if ((win = win_find(dpy,ev->xunmap.window,0)) &&
- win->sys->state == st_show) {
+ if ((win = win_find(dpy,xe->xunmap.window,0)) &&
+ win->sys->state == ST_SHOW) {
if (!strut_del(root, win))
wm_remove(win);
else
wm_update();
- win->sys->state = st_hide;
+ win->sys->state = ST_HIDE;
}
}
else if (type == DestroyNotify) {
//printf("destroy: %d\n", type);
- if ((win = win_find(dpy,ev->xdestroywindow.window,0)))
+ if ((win = win_find(dpy,xe->xdestroywindow.window,0)))
win_remove(win);
}
else if (type == ConfigureRequest) {
- XConfigureRequestEvent *cre = &ev->xconfigurerequest;
+ XConfigureRequestEvent *cre = &xe->xconfigurerequest;
printf("configure_req: %d - %x, (0x%lx) %dx%d @ %d,%d\n",
type, (int)cre->window, cre->value_mask,
cre->height, cre->width, cre->x, cre->y);
/* This seems necessary for, but causes flicker
* there could be a better way to do this */
- if ((win = win_find(dpy,ev->xmaprequest.window,0)))
+ if ((win = win_find(dpy,xe->xmaprequest.window,0)))
sys_move(win, win->x, win->y, win->w, win->h);
}
else if (type == MapRequest) {
printf("map_req: %d\n", type);
- if ((win = win_find(dpy,ev->xmaprequest.window,1))) {
+ if ((win = win_find(dpy,xe->xmaprequest.window,1))) {
if (!strut_add(root, win))
wm_insert(win);
else
wm_update();
}
- XMapWindow(dpy,ev->xmaprequest.window);
+ XMapWindow(dpy,xe->xmaprequest.window);
}
else {
printf("unknown event: %d\n", type);
void sys_move(win_t *win, int x, int y, int w, int h)
{
//printf("sys_move: %p - %d,%d %dx%d\n", win, x, y, w, h);
- int b = 2*BORDER;
+ int b = 2*border;
win->x = x; win->y = y;
win->w = MAX(w,1+b); win->h = MAX(h,1+b);
w = MAX(w-b,1); h = MAX(h-b,1);
/* Flush events, so moving window doesn't cause re-focus
* There's probably a better way to do this */
- XEvent ev;
+ XEvent xe;
XSync(win->sys->dpy, False);
- while (XCheckMaskEvent(win->sys->dpy, EnterWindowMask|LeaveWindowMask, &ev))
+ while (XCheckMaskEvent(win->sys->dpy, EnterWindowMask|LeaveWindowMask, &xe))
printf("Skipping enter/leave event\n");
}
/* Set border on focused window */
static win_t *last = NULL;
if (last)
- XSetWindowBorder(last->sys->dpy, last->sys->xid, colors[clr_unfocus]);
- XSetWindowBorder(win->sys->dpy, win->sys->xid, colors[clr_focus]);
- XSetWindowBorderWidth(win->sys->dpy, win->sys->xid, BORDER);
+ XSetWindowBorder(last->sys->dpy, last->sys->xid, colors[CLR_UNFOCUS]);
+ XSetWindowBorder(win->sys->dpy, win->sys->xid, colors[CLR_FOCUS]);
+ XSetWindowBorderWidth(win->sys->dpy, win->sys->xid, border);
last = win;
/* Set actual focus */
XSendEvent(win->sys->dpy, win->sys->xid, False, NoEventMask, &(XEvent){
.type = ClientMessage,
.xclient.window = win->sys->xid,
- .xclient.message_type = atoms[wm_proto],
+ .xclient.message_type = atoms[WM_PROTO],
.xclient.format = 32,
- .xclient.data.l[0] = atoms[wm_focus],
+ .xclient.data.l[0] = atoms[WM_FOCUS],
.xclient.data.l[1] = CurrentTime,
});
}
{
win->sys->state = state;
switch (state) {
- case st_show:
+ case ST_SHOW:
printf("sys_show: show\n");
XMapWindow(win->sys->dpy, win->sys->xid);
XSync(win->sys->dpy, False);
return;
- case st_full:
+ case ST_FULL:
printf("sys_show: full\n");
return;
- case st_shade:
+ case ST_SHADE:
printf("sys_show: shade\n");
return;
- case st_icon:
+ case ST_ICON:
printf("sys_show: icon\n");
return;
- case st_hide:
+ case ST_HIDE:
printf("sys_show: hide\n");
XUnmapWindow(win->sys->dpy, win->sys->xid);
return;
}
}
-void sys_watch(win_t *win, Key_t key, mod_t mod)
+void sys_watch(win_t *win, event_t ev, mod_t mod)
{
- //printf("sys_watch: %p - %x %hhx\n", win, key, mod);
+ //printf("sys_watch: %p - %x %hhx\n", win, ev, mod);
XWindowAttributes attr;
XGetWindowAttributes(win->sys->dpy, win->sys->xid, &attr);
long mask = attr.your_event_mask;
- if (key_mouse0 <= key && key <= key_mouse7)
- XGrabButton(win->sys->dpy, btn2x(key), mod2x(mod), win->sys->xid, False,
+ if (EV_MOUSE0 <= ev && ev <= EV_MOUSE7)
+ XGrabButton(win->sys->dpy, ev2xb(ev), mod2x(mod), win->sys->xid, False,
mod.up ? ButtonReleaseMask : ButtonPressMask,
GrabModeAsync, GrabModeAsync, None, None);
- else if (key == key_enter)
+ else if (ev == EV_ENTER)
XSelectInput(win->sys->dpy, win->sys->xid, EnterWindowMask|mask);
- else if (key == key_leave)
+ else if (ev == EV_LEAVE)
XSelectInput(win->sys->dpy, win->sys->xid, LeaveWindowMask|mask);
- else if (key == key_focus || key == key_unfocus)
+ else if (ev == EV_FOCUS || ev == EV_UNFOCUS)
XSelectInput(win->sys->dpy, win->sys->xid, FocusChangeMask|mask);
else
- XGrabKey(win->sys->dpy, XKeysymToKeycode(win->sys->dpy, key2x(key)),
+ XGrabKey(win->sys->dpy, XKeysymToKeycode(win->sys->dpy, ev2xk(ev)),
mod2x(mod), win->sys->xid, True, GrabModeAsync, GrabModeAsync);
}
-void sys_unwatch(win_t *win, Key_t key, mod_t mod)
+void sys_unwatch(win_t *win, event_t ev, mod_t mod)
{
- if (key_mouse0 <= key && key <= key_mouse7)
- XUngrabButton(win->sys->dpy, btn2x(key), mod2x(mod), win->sys->xid);
+ if (EV_MOUSE0 <= ev && ev <= EV_MOUSE7)
+ XUngrabButton(win->sys->dpy, ev2xb(ev), mod2x(mod), win->sys->xid);
}
list_t *sys_info(win_t *win)
Window xid;
/* Load configuration */
- BORDER = conf_get_int("main.border", BORDER);
- NO_CAPTURE = conf_get_int("main.no-capture", NO_CAPTURE);
+ border = conf_get_int("main.border", border);
+ no_capture = conf_get_int("main.no-capture", no_capture);
/* Open the display */
if (!(dpy = XOpenDisplay(NULL)))
error("Unable to get root window");
/* Setup X11 data */
- atoms[wm_proto] = XInternAtom(dpy, "WM_PROTOCOLS", False);
- atoms[wm_focus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
- atoms[net_strut] = XInternAtom(dpy, "_NET_WM_STRUT", False);
+ atoms[WM_PROTO] = XInternAtom(dpy, "WM_PROTOCOLS", False);
+ atoms[WM_FOCUS] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
+ atoms[NET_STRUT] = XInternAtom(dpy, "_NET_WM_STRUT", False);
- colors[clr_focus] = get_color(dpy, "#a0a0ff");
- colors[clr_unfocus] = get_color(dpy, "#101066");
- colors[clr_urgent] = get_color(dpy, "#ff0000");
+ colors[CLR_FOCUS] = get_color(dpy, "#a0a0ff");
+ colors[CLR_UNFOCUS] = get_color(dpy, "#101066");
+ colors[CLR_URGENT] = get_color(dpy, "#ff0000");
printf("colors = #%06lx #%06lx #%06lx\n", colors[0], colors[1], colors[2]);
/* Select window management events */
void sys_run(win_t *root)
{
/* Add each initial window */
- if (!NO_CAPTURE) {
+ if (!no_capture) {
unsigned int nkids;
Window par, xid, *kids = NULL;
if (XQueryTree(root->sys->dpy, root->sys->xid,
running = 1;
while (running)
{
- XEvent ev;
- XNextEvent(root->sys->dpy, &ev);
- process_event(ev.type, &ev, root);
+ XEvent xe;
+ XNextEvent(root->sys->dpy, &xe);
+ process_event(xe.type, &xe, root);
}
}
/* Window states */
typedef enum {
- st_show, // show as regular window
- st_full, // fullscreen/maximized
- st_shade, // show titlebar only
- st_icon, // iconified/minimized
- st_hide, // completely hidden
+ ST_SHOW, // show as regular window
+ ST_FULL, // fullscreen/maximized
+ ST_SHADE, // show titlebar only
+ ST_ICON, // iconified/minimized
+ ST_HIDE, // completely hidden
} state_t;
/* Basic window type */
/* Generic key codes, also used for some other events
* Keys map to their Unicode value */
-typedef enum {
- key_alert = '\a',
- key_backspace = '\b',
- key_formfeed = '\f',
- key_newline = '\n',
- key_return = '\r',
- key_tab = '\t',
- key_vtab = '\v',
- key_singlequote = '\'',
- key_doublequote = '\"',
- key_backslash = '\\',
- key_question = '\?',
- key_none = 0xF0000, // unused Unicode space
- key_mouse0, key_mouse1, key_mouse2, key_mouse3,
- key_mouse4, key_mouse5, key_mouse6, key_mouse7,
- key_left, key_right, key_up, key_down,
- key_home, key_end, key_pageup, key_pagedown,
- key_f1, key_f2, key_f3, key_f4,
- key_f5, key_f6, key_f7, key_f8,
- key_f9, key_f10, key_f11, key_f12,
- key_alt, key_ctrl, key_shift, key_win,
- key_enter, key_leave, key_focus, key_unfocus,
-} Key_t;
+typedef int event_t;
+enum {
+ EV_ALERT = '\a',
+ EV_BACKSPACE = '\b',
+ EV_FORMFEED = '\f',
+ EV_NEWLINE = '\n',
+ EV_RETURN = '\r',
+ EV_TAB = '\t',
+ EV_VTAB = '\v',
+ EV_SINGLEQUOTE = '\'',
+ EV_DOUBLEQUOTE = '\"',
+ EV_BACKSLASH = '\\',
+ EV_QUESTION = '\?',
+ EV_NONE = 0xF0000, // unused Unicode space
+ EV_MOUSE0, EV_MOUSE1, EV_MOUSE2, EV_MOUSE3,
+ EV_MOUSE4, EV_MOUSE5, EV_MOUSE6, EV_MOUSE7,
+ EV_LEFT, EV_RIGHT, EV_UP, EV_DOWN,
+ EV_HOME, EV_END, EV_PAGEUP, EV_PAGEDOWN,
+ EV_F1, EV_F2, EV_F3, EV_F4,
+ EV_F5, EV_F6, EV_F7, EV_F8,
+ EV_F9, EV_F10, EV_F11, EV_F12,
+ EV_ALT, EV_CTRL, EV_SHIFT, EV_WIN,
+ EV_ENTER, EV_LEAVE, EV_FOCUS, EV_UNFOCUS,
+};
/* Key modifiers, up is for button release */
typedef struct {
/* Set the windows drawing state */
void sys_show(win_t *win, state_t st);
-/* Start watching for a key events. The sys subsequently
- * calls wm_handle_key whenever the event occurs. */
-void sys_watch(win_t *win, Key_t key, mod_t mod);
+/* Start watching for an event. The sys subsequently
+ * calls wm_handle_event whenever the event occurs. */
+void sys_watch(win_t *win, event_t ev, mod_t mod);
-/* Stop watching a key event */
-void sys_unwatch(win_t *win, Key_t key, mod_t mod);
+/* Stop watching an event */
+void sys_unwatch(win_t *win, event_t event, mod_t mod);
/* Return a list of windows representing the geometry of the
* physical displays attached to the computer. */
{
}
-int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr)
+int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr)
{
- int new = key - '0';
+ int new = ev - '0';
if (!win || !mod.MODKEY || mod.up || new == tag ||
- key < '0' || key > '9')
+ ev < '0' || ev > '9')
return 0;
if (mod.shift) {
return 0;
tags[tag] = list_remove(tags[tag], node, 0);
tags[new] = list_insert(tags[new], win);
- sys_show(win, st_hide);
+ sys_show(win, ST_HIDE);
} else {
for (list_t *cur = tags[new]; cur; cur = cur->next)
- sys_show(cur->data, st_show);
+ sys_show(cur->data, ST_SHOW);
for (list_t *cur = tags[tag]; cur; cur = cur->next)
- sys_show(cur->data, st_hide);
+ sys_show(cur->data, ST_HIDE);
tag = new;
}
return 1;
void wm_init(win_t *root)
{
- Key_t keys[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
+ event_t keys[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
for (int i = 0; i < countof(keys); i++) {
sys_watch(root, keys[i], MOD(.MODKEY=1));
sys_watch(root, keys[i], MOD(.MODKEY=1,.shift=1));
{
for (int i = 0; i < 10; i++) {
while (tags[i]) {
- sys_show(tags[i]->data, st_show);
+ sys_show(tags[i]->data, ST_SHOW);
tags[i] = list_remove(tags[i], tags[i], 0);
}
}
#ifndef MODKEY
#define MODKEY alt
#endif
-static int MARGIN = 0;
-static int STACK = 25;
+static int margin = 0;
+static int stack = 25;
/* Enums */
typedef enum {
- none, move, resize
+ NONE, MOVE, RESIZE
} drag_t;
typedef enum {
- split, stack, max, tab
+ SPLIT, STACK, FULL, TAB
} mode_t;
typedef enum {
- tiling, floating
+ TILING, FLOATING
} layer_t;
/* Window structure types */
if (!wm_tag || !wm_dpy)
return NULL;
switch (wm_dpy->layer) {
- case tiling:
+ case TILING:
return wm_col && wm_row ? wm_row->win : NULL;
- case floating:
+ case FLOATING:
return wm_flt ? wm_flt->win : NULL;
}
return NULL;
if (_dpy) *_dpy = dpy;
if (_col) *_col = col;
if (_row) *_row = row;
- return tiling;
+ return TILING;
}
}
tag_foreach_flt(tag, dpy, flt, win) {
if (win == target) {
if (_dpy) *_dpy = dpy;
if (_flt) *_flt = flt;
- return floating;
+ return FLOATING;
}
}
return -1;
{
list_t *dpy, *col, *row, *flt;
switch (searchl(tag, target, &dpy, &col, &row, &flt)) {
- case tiling:
+ case TILING:
if (_dpy) *_dpy = DPY(dpy);
if (_col) *_col = COL(col);
if (_row) *_row = ROW(row);
- return tiling;
- case floating:
+ return TILING;
+ case FLOATING:
if (_dpy) *_dpy = DPY(dpy);
if (_flt) *_flt = FLT(flt);
- return floating;
+ return FLOATING;
}
return -1;
}
static void set_mode(win_t *win, mode_t mode)
{
col_t *col;
- if (tiling != search(wm_tag, win, NULL, &col, NULL, NULL))
+ if (TILING != search(wm_tag, win, NULL, &col, NULL, NULL))
return;
printf("set_mode: %p, %d -> %d\n",
col, col->mode, mode);
col->mode = mode;
- if (col->mode == split)
+ if (col->mode == SPLIT)
for (list_t *cur = col->rows; cur; cur = cur->next) {
row_t *row = cur->data;
row->height = wm_dpy->geom->h;
* this prevents stealing all mouse clicks from client windows,
* - A better way may be to re-send mouse clicks to client windows
* using the return value from wm_handle_key */
- for (int i = key_mouse1; i < key_mouse7; i++) {
+ for (int i = EV_MOUSE1; i < EV_MOUSE7; i++) {
if (wm_focus)
sys_watch(wm_focus, i, MOD());
sys_unwatch(win, i, MOD());
dpy_t *dpy; col_t *col; row_t *row; flt_t *flt;
switch (search(wm_tag, win, &dpy, &col, &row, &flt)) {
- case tiling:
+ case TILING:
wm_dpy = dpy;
wm_col = col;
wm_row = row;
- dpy->layer = tiling;
+ dpy->layer = TILING;
break;
- case floating:
+ case FLOATING:
wm_dpy = dpy;
wm_flt = flt;
- dpy->layer = floating;
+ dpy->layer = FLOATING;
break;
}
sys_focus(win);
printf("set_move: %d - %p@%d,%d\n",
drag, win, ptr.rx, ptr.ry);
move_mode = drag;
- if (drag == move || drag == resize) {
+ if (drag == MOVE || drag == RESIZE) {
move_layer = searchl(wm_tag, win, NULL,
&move_lcol, &move_lrow, &move_lflt);
if (move_layer < 0)
win_t *geom = dpy->geom;
printf(" dpy: <%-9p [%p->%p] >%-9p %c=%-9p - %d,%d %dx%d\n",
ldpy->prev, ldpy, ldpy->data, ldpy->next,
- dpy->layer == tiling ? 'c' : 'f',
- dpy->layer == tiling ? (void*)dpy->col : (void*)dpy->flt,
+ dpy->layer == TILING ? 'c' : 'f',
+ dpy->layer == TILING ? (void*)dpy->col : (void*)dpy->flt,
geom->x, geom->y, geom->h, geom->w);
for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next) {
col_t *col = lcol->data;
list_t *ldpy, *lcol, *lrow, *lflt;
layer_t layer = searchl(tag, win, &ldpy, &lcol, &lrow, &lflt);
- if (layer == tiling) {
+ if (layer == TILING) {
dpy_t *dpy = DPY(ldpy);
col_t *col = COL(lcol);
col->row = lrow->prev ? lrow->prev->data :
}
}
- if (layer == floating) {
+ if (layer == FLOATING) {
dpy_t *dpy = DPY(ldpy);
dpy->flts = list_remove(dpy->flts, lflt, 1);
dpy->flt = dpy->flts ? list_last(dpy->flts)->data : NULL;
if (!dpy->flt && dpy->col && dpy->col->row)
- dpy->layer = tiling;
+ dpy->layer = TILING;
}
return layer;
tag->dpy = dpy;
tag->dpy->col = col;
tag->dpy->col->row = row;
- tag->dpy->layer = tiling;
+ tag->dpy->layer = TILING;
row->height = dpy->geom->h / MAX(nrows,1);
if (nrows == 0) {
dpy->flts = list_append(dpy->flts, flt);
tag->dpy = dpy;
tag->dpy->flt = flt;
- tag->dpy->layer = floating;
+ tag->dpy->layer = FLOATING;
}
/* Insert a window into a tag */
static void put_win(win_t *win, tag_t *tag, layer_t layer)
{
- if (layer == tiling)
+ if (layer == TILING)
put_win_col(win, tag, tag->dpy, tag->dpy->col);
- if (layer == floating)
+ if (layer == FLOATING)
put_win_flt(win, tag, tag->dpy);
}
print_txt();
printf("shift_window: >>>\n");
list_t *ldpy, *lcol, *lrow, *lflt;
- if (tiling != searchl(wm_tag, win, &ldpy, &lcol, &lrow, &lflt))
+ if (TILING != searchl(wm_tag, win, &ldpy, &lcol, &lrow, &lflt))
return;
dpy_t *dpy = ldpy->data;
if (row != 0) {
if (rows != 0 && wm_focus) {
/* Move focus up/down */
list_t *dpy, *col, *row;
- if (tiling != searchl(wm_tag, wm_focus, &dpy, &col, &row, NULL))
+ if (TILING != searchl(wm_tag, wm_focus, &dpy, &col, &row, NULL))
return;
row_t *next = get_next(row, rows > 0)->data;
set_focus(next->win);
- if (COL(col)->mode != split)
+ if (COL(col)->mode != SPLIT)
wm_update();
}
if (cols != 0) {
list_t *dpy, *col, *row, *ndpy, *ncol = NULL;
if (wm_focus) {
/* Currently focused on a window */
- if (tiling != searchl(wm_tag, wm_focus, &dpy, &col, &row, NULL))
+ if (TILING != searchl(wm_tag, wm_focus, &dpy, &col, &row, NULL))
return;
ncol = cols > 0 ? col->next : col->prev;
} else {
/* Scale horizontally */
x = dpy->geom->x;
- mx = dpy->geom->w - (list_length(dpy->cols)+1)*MARGIN;
+ mx = dpy->geom->w - (list_length(dpy->cols)+1)*margin;
for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next)
tx += COL(lcol)->width;
for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next)
for (list_t *lrow = col->rows; lrow; lrow = lrow->next)
ty += ROW(lrow)->height;
y = dpy->geom->y;
- my = dpy->geom->h - (MARGIN + (nrows-1)* MARGIN + MARGIN);
- sy = dpy->geom->h - (MARGIN + (nrows-1)*(MARGIN/2) + MARGIN)
- - (nrows-1)* STACK;
+ my = dpy->geom->h - (margin + (nrows-1)* margin + margin);
+ sy = dpy->geom->h - (margin + (nrows-1)*(margin/2) + margin)
+ - (nrows-1)* stack;
for (list_t *lrow = col->rows; lrow; lrow = lrow->next) {
win_t *win = ROW(lrow)->win;
win->h = ROW(lrow)->height;
- state_t state = st_show;
+ state_t state = ST_SHOW;
int height = 0;
switch (col->mode) {
- case split:
- sys_move(win, x+MARGIN, y+MARGIN,
+ case SPLIT:
+ sys_move(win, x+margin, y+margin,
col->width, win->h * ((float)my / ty));
height = win->h;
- y += height + MARGIN;
+ y += height + margin;
break;
- case stack:
+ case STACK:
if (lrow->next && ROW(lrow->next)->win == col->row->win) {
/* Hack to prevent flashing */
win_t *next = ROW(lrow->next)->win;
- sys_move(next, x+MARGIN, y+MARGIN+STACK+MARGIN/2,
+ sys_move(next, x+margin, y+margin+stack+margin/2,
col->width, sy);
- sys_show(next, st_show);
+ sys_show(next, ST_SHOW);
}
int isfocus = win == col->row->win;
- state = isfocus ? st_show : st_shade;
+ state = isfocus ? ST_SHOW : ST_SHADE;
sys_show(win, state);
- sys_move(win, x+MARGIN, y+MARGIN, col->width, sy);
- y += (isfocus ? sy : STACK) + (MARGIN/2);
+ sys_move(win, x+margin, y+margin, col->width, sy);
+ y += (isfocus ? sy : stack) + (margin/2);
break;
- case max:
- case tab:
- sys_move(win, x+MARGIN, 0+MARGIN,
- col->width, dpy->geom->h-2*MARGIN);
+ case FULL:
+ case TAB:
+ sys_move(win, x+margin, 0+margin,
+ col->width, dpy->geom->h-2*margin);
break;
}
ROW(lrow)->state = state;
sys_raise(win);
ROW(lrow)->height = win->h;
}
- x += col->width + MARGIN;
+ x += col->width + margin;
}
}
for (list_t *tag = wm ->tags; tag; tag = tag->next)
if (tag->data != wm_tag) {
tag_foreach_col(TAG(tag), dpy, col, row, win)
- sys_show(win, st_hide);
+ sys_show(win, ST_HIDE);
tag_foreach_flt(TAG(tag), dpy, flt, win)
- sys_show(win, st_hide);
+ sys_show(win, ST_HIDE);
}
/* Refresh the display */
set_focus(wm_focus);
}
-int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr)
+int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr)
{
if (!win || win == wm_dpy->geom) return 0;
- //printf("wm_handle_key: %p - %x %c%c%c%c%c\n", win, key,
+ //printf("wm_handle_event: %p - %x %c%c%c%c%c\n", win, ev,
// mod.up ? '^' : 'v',
// mod.alt ? 'a' : '-',
// mod.ctrl ? 'c' : '-',
// mod.win ? 'w' : '-');
/* Mouse movement */
- if (key == key_mouse1)
+ if (ev == EV_MOUSE1)
raise_float(win);
- if (key_mouse0 <= key && key <= key_mouse7) {
- if (key == key_mouse1 && mod.MODKEY && !mod.up)
- return set_move(win,ptr,move), 1;
- if (key == key_mouse3 && mod.MODKEY && !mod.up)
- return set_move(win,ptr,resize), 1;
- if (move_mode != none && mod.up)
- return set_move(win,ptr,none), 1;
- if (key == key_mouse1 && !mod.up && win->state == st_shade)
+ if (EV_MOUSE0 <= ev && ev <= EV_MOUSE7) {
+ if (ev == EV_MOUSE1 && mod.MODKEY && !mod.up)
+ return set_move(win,ptr,MOVE), 1;
+ if (ev == EV_MOUSE3 && mod.MODKEY && !mod.up)
+ return set_move(win,ptr,RESIZE), 1;
+ if (move_mode != NONE && mod.up)
+ return set_move(win,ptr,NONE), 1;
+ if (ev == EV_MOUSE1 && !mod.up && win->state == ST_SHADE)
return set_focus(win), wm_update(), 0;
return 0;
}
/* Misc */
if (mod.MODKEY) {
#ifdef DEBUG
- if (key == key_f1) return raise_float(win), 1;
- if (key == key_f2) return set_focus(win), 1;
- if (key == key_f3) return sys_show(win, st_show), 1;
- if (key == key_f4) return sys_show(win, st_hide), 1;
- if (key == key_f7) return sys_show(win, st_shade), 1;
+ if (ev == EV_F1) return raise_float(win), 1;
+ if (ev == EV_F2) return set_focus(win), 1;
+ if (ev == EV_F3) return sys_show(win, ST_SHOW), 1;
+ if (ev == EV_F4) return sys_show(win, ST_HIDE), 1;
+ if (ev == EV_F7) return sys_show(win, ST_SHADE), 1;
#endif
- if (key == key_f5) return wm_update(), 1;
- if (key == key_f6) return print_txt(), 1;
- if (key == 'q') return sys_exit(), 1;
+ if (ev == EV_F5) return wm_update(), 1;
+ if (ev == EV_F6) return print_txt(), 1;
+ if (ev == 'q') return sys_exit(), 1;
}
/* Floating layer */
- if (key == ' ') {
+ if (ev == ' ') {
if (mod.MODKEY && mod.shift)
return set_layer(win), 1;
if (mod.MODKEY)
/* Movement commands */
if (mod.MODKEY && mod.shift) {
- switch (key) {
+ switch (ev) {
case 'h': return shift_window(wm_focus,-1, 0), 1;
case 'j': return shift_window(wm_focus, 0,+1), 1;
case 'k': return shift_window(wm_focus, 0,-1), 1;
}
}
else if (mod.MODKEY) {
- switch (key) {
+ switch (ev) {
case 'h': return shift_focus(-1, 0), 1;
case 'j': return shift_focus( 0,+1), 1;
case 'k': return shift_focus( 0,-1), 1;
/* Column mode commands */
if (mod.MODKEY) {
- switch (key) {
- case 'd': return set_mode(win, split), 1;
- case 's': return set_mode(win, stack), 1;
- case 'm': return set_mode(win, max), 1;
- case 't': return set_mode(win, tab), 1;
+ switch (ev) {
+ case 'd': return set_mode(win, SPLIT), 1;
+ case 's': return set_mode(win, STACK), 1;
+ case 'm': return set_mode(win, FULL), 1;
+ case 't': return set_mode(win, TAB), 1;
default: break;
}
}
/* Tag switching */
- if (mod.MODKEY && '0' <= key && key <= '9') {
- int name = key - '0';
+ if (mod.MODKEY && '0' <= ev && ev <= '9') {
+ int name = ev - '0';
if (mod.shift)
tag_set(win, name);
else
}
/* Focus change */
- if (key == key_enter && win->state != st_shade)
+ if (ev == EV_ENTER && win->state != ST_SHADE)
return set_focus(win), 1;
- if (key_mouse0 <= key && key <= key_mouse7)
+ if (EV_MOUSE0 <= ev && ev <= EV_MOUSE7)
return set_focus(win), 0;
/* Reset focus after after focus change,
* not sure what is causing the focus change in the first place
* but preventing that would be a better solution */
- if (key == key_focus)
+ if (ev == EV_FOCUS)
sys_focus(wm_focus ?: wm->root);
return 0;
//printf("wm_handle_ptr: %p - %d,%d %d,%d (%d) -- \n",
// cwin, ptr.x, ptr.y, ptr.rx, ptr.ry, move_mode);
- if (move_mode == none)
+ if (move_mode == NONE)
return 0;
int dx = ptr.rx - move_prev.rx;
int dy = ptr.ry - move_prev.ry;
move_prev = ptr;
- if (move_layer == tiling && move_mode == resize) {
+ if (move_layer == TILING && move_mode == RESIZE) {
list_t *vert = move_dir.v < 0 ? move_lrow->prev : move_lrow->next;
list_t *horz = move_dir.h < 0 ? move_lcol->prev : move_lcol->next;
if (vert) {
wm_update();
}
- if (move_layer == floating) {
+ if (move_layer == FLOATING) {
flt_t *flt = move_lflt->data;
win_t *win = flt->win;
- if (move_mode == move)
+ if (move_mode == MOVE)
sys_move(win, win->x+dx, win->y+dy, win->w, win->h);
- else if (move_mode == resize)
+ else if (move_mode == RESIZE)
sys_move(win,
win->x + dx * (move_dir.h < 0),
win->y + dy * (move_dir.v < 0),
/* Initialize window */
win->wm = new0(win_wm_t);
- sys_watch(win, key_enter, MOD());
- sys_watch(win, key_focus, MOD());
+ sys_watch(win, EV_ENTER, MOD());
+ sys_watch(win, EV_FOCUS, MOD());
/* Add to screen */
put_win(win, wm_tag, wm_dpy->layer);
printf("wm_init: %p\n", root);
/* Load configuration */
- MARGIN = conf_get_int("main.margin", MARGIN);
- STACK = conf_get_int("main.stack", STACK);
+ margin = conf_get_int("main.margin", margin);
+ stack = conf_get_int("main.stack", stack);
wm = new0(wm_t);
wm->root = root;
wm->tag = tag_new(wm->screens, 1);
wm->tags = list_insert(NULL, wm->tag);
- Key_t keys_e[] = {key_enter, key_focus};
- Key_t keys_s[] = {'h', 'j', 'k', 'l', 'q', ' ',
+ event_t ev_e[] = {EV_ENTER, EV_FOCUS};
+ event_t ev_s[] = {'h', 'j', 'k', 'l', 'q', ' ',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
- Key_t keys_m[] = {'h', 'j', 'k', 'l', 'd', 's', 'm', 't', ' ',
+ event_t ev_m[] = {'h', 'j', 'k', 'l', 'd', 's', 'm', 't', ' ',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- key_f1, key_f2, key_f3, key_f4, key_f5, key_f6,
- key_f7, key_f8, key_f9, key_f10, key_f11, key_f12,
- key_mouse1, key_mouse3};
- for (int i = 0; i < countof(keys_e); i++)
- sys_watch(root, keys_e[i], MOD());
- for (int i = 0; i < countof(keys_m); i++)
- sys_watch(root, keys_m[i], MOD(.MODKEY=1));
- for (int i = 0; i < countof(keys_s); i++)
- sys_watch(root, keys_s[i], MOD(.MODKEY=1,.shift=1));
+ EV_F1, EV_F2, EV_F3, EV_F4, EV_F5, EV_F6,
+ EV_F7, EV_F8, EV_F9, EV_F10, EV_F11, EV_F12,
+ EV_MOUSE1, EV_MOUSE3};
+ for (int i = 0; i < countof(ev_e); i++)
+ sys_watch(root, ev_e[i], MOD());
+ for (int i = 0; i < countof(ev_m); i++)
+ sys_watch(root, ev_m[i], MOD(.MODKEY=1));
+ for (int i = 0; i < countof(ev_s); i++)
+ sys_watch(root, ev_s[i], MOD(.MODKEY=1,.shift=1));
}
void wm_free(win_t *root)
while (tag->dpys) { dpy_t *dpy = tag->dpys->data;
while (dpy->cols) { col_t *col = dpy->cols->data;
while (col->rows) { row_t *row = col->rows->data;
- sys_show(row->win, st_show);
+ sys_show(row->win, ST_SHOW);
free(row->win->wm);
col->rows = list_remove(col->rows, col->rows, 1); }
dpy->cols = list_remove(dpy->cols, dpy->cols, 1); }
while (dpy->flts) { flt_t *flt = dpy->flts->data;
- sys_show(flt->win, st_show);
+ sys_show(flt->win, ST_SHOW);
free(flt->win->wm);
dpy->flts = list_remove(dpy->flts, dpy->flts, 1); }
tag->dpys = list_remove(tag->dpys, tag->dpys, 1); }
/* Refresh the window layout */
void wm_update(void);
-/* Called for each watched key press.
- * This is currently used for some other events such
- * as focus-in and focus-out as well. */
-int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr);
+/* Called for each watched event */
+int wm_handle_event(win_t *win, event_t ev, mod_t mod, ptr_t ptr);
/* Called for each mouse movement */
int wm_handle_ptr(win_t *win, ptr_t ptr);