wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 5fc1892c9fe1bc1cb3ddb80877a9086f161999ee
parent 80fe6d9531782a913856996e3c3dafd563c15050
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Thu, 26 Jan 2006 13:56:28 +0200

proceeded with event.c and mouse.c


Diffstat:
cmd/wm/client.c | 8++++----
cmd/wm/event.c | 84++++++++++++++++++++++++++++++++-----------------------------------------------
cmd/wm/mouse.c | 40++++++++++++++++++++--------------------
cmd/wm/wm.c | 24++++++++++++------------
cmd/wm/wm.h | 18++++++++++--------
5 files changed, 80 insertions(+), 94 deletions(-)

diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -189,7 +189,7 @@ unmap_client(Client * c) void reparent_client(Client *c, Window w, int x, int y) { - c->framed = w == c->frame.win; + c->attached = w == c->frame.win; XReparentWindow(dpy, c->win, w, x, y); c->ignore_unmap++; } @@ -226,7 +226,7 @@ configure_client(Client * c) e.window = c->win; e.x = c->rect.x; e.y = c->rect.y; - if(c->framed) { + if(c->attached) { e.x += c->frame.rect.x; e.y += c->frame.rect.y; } @@ -268,7 +268,7 @@ handle_client_property(Client *c, XPropertyEvent *e) cext_strlcpy(c->name, (char*) name.value, sizeof(c->name)); free(name.value); } - if(c->framed) + if(c->attached) draw_client(c); invoke_wm_event(def[WM_EVENT_CLIENT_UPDATE]); break; @@ -448,7 +448,7 @@ detach_client(Client *c, Bool unmap) c->page = nil; if(c->destroyed) destroy_client(c); - focus_page(sel_page); + focus_page(pages[sel_page]); } Client * diff --git a/cmd/wm/event.c b/cmd/wm/event.c @@ -63,7 +63,7 @@ handle_buttonpress(XEvent * e) if((c == win_to_frame(ev->window))) { focus_client(c); - if(e->button == Button1) { + if(ev->button == Button1) { align = cursor_to_align(c->frame.cursor); if(align == CENTER) mouse_move(c); @@ -71,31 +71,27 @@ handle_buttonpress(XEvent * e) mouse_resize(c, align); return; } - bindex = WM_EVENT_B2PRESS - 2 + e->button; + bindex = WM_EVENT_B2PRESS - 2 + ev->button; /* frame mouse handling */ if(def[bindex]->content) wmii_spawn(dpy, def[bindex]->content); } else if((c = win_to_client(ev->window))) { - Layout *l = sel_layout(); - if(l != c->frame->layout) - focus_layout(c->frame->layout); - l = c->frame->layout; - l->def->focus(l, c, False); + focus_client(c); ev->state &= valid_mask; if(ev->state & Mod1Mask) { Align align; - XRaiseWindow(dpy, c->frame->win); + XRaiseWindow(dpy, c->frame.win); switch (ev->button) { case Button1: - mouse_move(c->frame); + mouse_move(c); break; case Button3: align = xy_to_align(&c->rect, ev->x, ev->y); if(align == CENTER) - mouse_move(c->frame); + mouse_move(c); else - mouse_resize(c->frame, align); + mouse_resize(c, align); break; default: break; @@ -111,18 +107,14 @@ handle_configurerequest(XEvent * e) XWindowChanges wc; Client *c; unsigned int bw = 0, tabh = 0; - Frame *f = 0; - c = win_to_client(ev->window); ev->value_mask &= ~CWSibling; if(c) { - f = c->frame; - - if(f) { - bw = border_width(f); - tabh = tab_height(f); + if(c->attached) { + bw = border_width(c); + tabh = tab_height(c); } if(ev->value_mask & CWStackMode) { if(wc.stack_mode == Above) @@ -145,23 +137,22 @@ handle_configurerequest(XEvent * e) gravitate(c, tabh ? tabh : bw, bw, 0); - if(f) { - f->rect.x = wc.x = c->rect.x - bw; - f->rect.y = wc.y = c->rect.y - (tabh ? tabh : bw); - f->rect.width = wc.width = c->rect.width + 2 * bw; - f->rect.height = wc.height = - c->rect.height + bw + (tabh ? tabh : bw); + if(c->attached) { + c->frame.rect.x = wc.x = c->rect.x - bw; + c->frame.rect.y = wc.y = c->rect.y - (tabh ? tabh : bw); + c->frame.rect.width = wc.width = c->rect.width + 2 * bw; + c->frame.rect.height = wc.height = c->rect.height + bw + (tabh ? tabh : bw); wc.border_width = 1; wc.sibling = None; wc.stack_mode = ev->detail; - XConfigureWindow(dpy, f->win, ev->value_mask, &wc); + XConfigureWindow(dpy, c->frame.win, ev->value_mask, &wc); configure_client(c); } } wc.x = ev->x; wc.y = ev->y; - if(f) { + if(c && c->attached) { /* if so, then bw and tabh are already initialized */ wc.x = bw; wc.y = tabh ? tabh : bw; @@ -177,8 +168,7 @@ handle_configurerequest(XEvent * e) wc.stack_mode = Above; ev->value_mask &= ~CWStackMode; ev->value_mask |= CWBorderWidth; - XConfigureWindow(dpy, e->xconfigurerequest.window, ev->value_mask, - &wc); + XConfigureWindow(dpy, e->xconfigurerequest.window, ev->value_mask, &wc); XSync(dpy, False); } @@ -197,11 +187,10 @@ handle_destroynotify(XEvent * e) static void handle_expose(XEvent * e) { - static Frame *f; + static Client *c; if(e->xexpose.count == 0) { - f = win_to_frame(e->xbutton.window); - if(f) - draw_frame(f); + if((c = win_to_frame(e->xbutton.window))) + draw_client(c); } } @@ -221,33 +210,28 @@ handle_maprequest(XEvent * e) } /* attach heuristic support */ - if(attachqueue && (attachqueue->page != selpage)) { - MapQueue *r = attachqueue; - focus_page(r->page); - attachqueue = attachqueue->next; - free(r); + if(aqueuesz && aqueue[0]) { + focus_page(0); + detach_page_from_array(aqueue[0], aqueue); } - /* there're client which send map requests twice */ + /* there're clients which send map requests twice */ c = win_to_client(ev->window); if(!c) - c = alloc_client(ev->window); - if(!c->frame) { - init_client(c, &wa); + c = alloc_client(ev->window, &wa); + if(!c->attached) attach_client(c); - } } static void handle_motionnotify(XEvent * e) { - Frame *f = win_to_frame(e->xmotion.window); - Cursor cursor; - if(f) { - cursor = cursor_for_motion(f, e->xmotion.x, e->xmotion.y); - if(cursor != f->cursor) { - f->cursor = cursor; - XDefineCursor(dpy, f->win, cursor); + Client *c = win_to_frame(e->xmotion.window); + if(c) { + Cursor cursor = cursor_for_motion(c, e->xmotion.x, e->xmotion.y); + if(cursor != c->frame.cursor) { + c->frame.cursor = cursor; + XDefineCursor(dpy, c->frame.win, cursor); } } } @@ -285,7 +269,7 @@ static void handle_clientmessage(XEvent *e) if (ev->message_type == net_atoms[NET_NUMBER_OF_DESKTOPS] && ev->format == 32) return; /* ignore */ else if (ev->message_type == net_atoms[NET_CURRENT_DESKTOP] && ev->format == 32) { - focus_page(pageat(ev->data.l[0])); + focus_page(pages[ev->data.l[0]]); return; } } diff --git a/cmd/wm/mouse.c b/cmd/wm/mouse.c @@ -8,27 +8,27 @@ #include "wm.h" Cursor -cursor_for_motion(Frame * f, int x, int y) +cursor_for_motion(Client *c, int x, int y) { int n, e, w, s, tn, te, tw, ts; int tabh, bw; - bw = border_width(f); - tabh = tab_height(f); + bw = border_width(c); + tabh = tab_height(c); - if(!f || !bw) + if(!bw) return normal_cursor; /* rectangle attributes of client are used */ w = x < bw; - e = x >= f->rect.width - bw; + e = x >= c->frame.rect.width - bw; n = y < bw; - s = y >= f->rect.height - bw; + s = y >= c->frame.rect.height - bw; tw = x < (tabh ? tabh : 2 * bw); - te = x > f->rect.width - (tabh ? tabh : 2 * bw); + te = x > c->frame.rect.width - (tabh ? tabh : 2 * bw); tn = y < (tabh ? tabh : 2 * bw); - ts = s > f->rect.height - (tabh ? tabh : 2 * bw); + ts = s > c->frame.rect.height - (tabh ? tabh : 2 * bw); if((w && n) || (w && tn) || (n && tw)) return nw_cursor; @@ -296,7 +296,7 @@ draw_pseudo_border(XRectangle * r) void -mouse_move(Frame * f) +mouse_move(Client *c) { int px = 0, py = 0, wex, wey, ex, ey, first = 1, i; Window dummy; @@ -311,11 +311,11 @@ mouse_move(Frame * f) unsigned int num; unsigned int dmask; XRectangle *rects = rectangles(&num); - XRectangle frect = f->rect; + XRectangle frect = c->frame.rect; XPoint pt; - XQueryPointer(dpy, f->win, &dummy, &dummy, &i, &i, &wex, &wey, &dmask); - XTranslateCoordinates(dpy, f->win, root, wex, wey, &ex, &ey, &dummy); + XQueryPointer(dpy, c->frame.win, &dummy, &dummy, &i, &i, &wex, &wey, &dmask); + XTranslateCoordinates(dpy, c->frame.win, root, wex, wey, &ex, &ey, &dummy); pt.x = ex; pt.y = ey; XSync(dpy, False); @@ -337,7 +337,7 @@ mouse_move(Frame * f) case ButtonRelease: if(!first) { draw_pseudo_border(&frect); - resize_frame(f, &frect, &pt); + resize_client(c, &frect, &pt); } free(rects); XUngrabPointer(dpy, CurrentTime /* ev.xbutton.time */ ); @@ -348,7 +348,7 @@ mouse_move(Frame * f) case MotionNotify: pt.x = ev.xmotion.x; pt.y = ev.xmotion.y; - XTranslateCoordinates(dpy, f->win, root, ev.xmotion.x, + XTranslateCoordinates(dpy, c->frame.win, root, ev.xmotion.x, ev.xmotion.y, &px, &py, &dummy); if(first) first = 0; @@ -545,7 +545,7 @@ snap_resize(XRectangle * r, XRectangle * o, Align align, void -mouse_resize(Frame * f, Align align) +mouse_resize(Client *c, Align align) { int px = 0, py = 0, i, ox, oy, first = 1; Window dummy; @@ -560,14 +560,14 @@ mouse_resize(Frame * f, Align align) unsigned int dmask; unsigned int num; XRectangle *rects = rectangles(&num); - XRectangle frect = f->rect; + XRectangle frect = c->frame.rect; XRectangle origin = frect; - XQueryPointer(dpy, f->win, &dummy, &dummy, &i, &i, &ox, &oy, &dmask); + XQueryPointer(dpy, c->frame.win, &dummy, &dummy, &i, &i, &ox, &oy, &dmask); XSync(dpy, False); XGrabServer(dpy); while(XGrabPointer - (dpy, f->win, False, ButtonMotionMask | ButtonReleaseMask, + (dpy, c->frame.win, False, ButtonMotionMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, resize_cursor, CurrentTime) != GrabSuccess) usleep(20000); @@ -586,7 +586,7 @@ mouse_resize(Frame * f, Align align) draw_pseudo_border(&frect); pt.x = px; pt.y = py; - resize_frame(f, &frect, &pt); + resize_client(c, &frect, &pt); } XUngrabPointer(dpy, CurrentTime /* ev.xbutton.time */ ); XUngrabServer(dpy); @@ -594,7 +594,7 @@ mouse_resize(Frame * f, Align align) return; break; case MotionNotify: - XTranslateCoordinates(dpy, f->win, root, ev.xmotion.x, + XTranslateCoordinates(dpy, c->frame.win, root, ev.xmotion.x, ev.xmotion.y, &px, &py, &dummy); if(first) diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c @@ -281,7 +281,7 @@ pager(void *obj, char *arg) XUnmapWindow(dpy, transient); if((i = handle_kpress(&ev.xkey)) != -1) if(i < j) - focus_page(i); + focus_page(pages[i]); XUngrabKeyboard(dpy, CurrentTime); XUngrabPointer(dpy, CurrentTime /* ev.xbutton.time */ ); return; @@ -289,7 +289,7 @@ pager(void *obj, char *arg) case ButtonPress: XUnmapWindow(dpy, transient); if(ev.xbutton.button == Button1) - focus_page(xy_to_pager_page(ev.xbutton.x, ev.xbutton.y)); + focus_page(pages[xy_to_pager_page(ev.xbutton.x, ev.xbutton.y)]); XUngrabKeyboard(dpy, CurrentTime); XUngrabPointer(dpy, CurrentTime /* ev.xbutton.time */ ); return; @@ -419,32 +419,32 @@ xdetach_client(void *obj, char *arg) static void xselect_page(void *obj, char *arg) { - size_t np; + size_t np, new = sel_page; for(np = 0; (np < pagessz) && pages[np]; np++); if(!np || !arg) return; if(!strncmp(arg, "prev", 5)) { - if(sel_page > 0) - for(sel_page = 0; pages[sel_page]; sel_page++); - sel_page--; + if(new > 0) + for(new = 0; pages[new]; new++); + new--; } else if(!strncmp(arg, "next", 5)) { - if(pages[sel_page + 1]) - sel_page++; + if(pages[new + 1]) + new++; else - sel_page = 0; + new = 0; } else { int idx = blitz_strtonum(arg, 0, np); if(idx < np) - sel_page = idx; + new = idx; } - focus_page(sel_page); + focus_page(pages[new]); } static void xdestroy_page(void *obj, char *arg) { - destroy_page(sel_page); + destroy_page(pages[sel_page]); } static void diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -106,7 +106,7 @@ struct Client { unsigned int ignore_unmap; Bool destroyed; Bool maximized; - Bool framed; + Bool attached; Bool managed; Window win; Window trans; @@ -200,17 +200,19 @@ void init_event_hander(); void check_event(Connection * c); /* mouse.c */ -void mouse_resize(Client * f, Align align); -void mouse_move(Client * f); -Cursor cursor_for_motion(Client * f, int x, int y); +void mouse_resize(Client *c, Align align); +void mouse_move(Client *c); +Cursor cursor_for_motion(Client *c, int x, int y); Align cursor_to_align(Cursor cursor); Align xy_to_align(XRectangle * rect, int x, int y); -void drop_move(Client * f, XRectangle * new, XPoint * pt); +void drop_move(Client *c, XRectangle *new, XPoint *pt); /* page.c */ -size_t alloc_page(); -void destroy_page(size_t idx); -void focus_page(size_t idx); +void attach_page_to_array(Page *p, Page **array, size_t *size); +void detach_page_from_array(Page *p, Page **array); +Page *alloc_page(); +void destroy_page(Page *p); +void focus_page(Page *p); XRectangle *rectangles(unsigned int *num); /* column.c */