From 37635d17832397ca8ea1037c1dbf110d260aba65 Mon Sep 17 00:00:00 2001 From: Ciaran Anscomb Date: Tue, 13 Oct 2009 07:11:02 +0000 Subject: [PATCH] Refactor client raise, lower, hide and show --- client.c | 27 +++++++++++++++++++++++++-- events.c | 12 +++++------- evilwm.h | 8 ++++---- ewmh.c | 10 ---------- new.c | 3 ++- screen.c | 47 ++++++++++++++--------------------------------- 6 files changed, 50 insertions(+), 57 deletions(-) diff --git a/client.c b/client.c index 3ac4892..c370574 100644 --- a/client.c +++ b/client.c @@ -23,6 +23,29 @@ Client *find_client(Window w) { return NULL; } +void client_hide(Client *c) { + c->ignore_unmap++; /* Ignore unmap so we don't remove client */ + XUnmapWindow(dpy, c->parent); + set_wm_state(c, IconicState); +} + +void client_show(Client *c) { + XMapWindow(dpy, c->parent); + set_wm_state(c, NormalState); +} + +void client_raise(Client *c) { + XRaiseWindow(dpy, c->parent); + clients_stacking_order = list_to_tail(clients_stacking_order, c); + ewmh_set_net_client_list_stacking(c->screen); +} + +void client_lower(Client *c) { + XLowerWindow(dpy, c->parent); + clients_stacking_order = list_to_head(clients_stacking_order, c); + ewmh_set_net_client_list_stacking(c->screen); +} + void set_wm_state(Client *c, int state) { /* Using "long" for the type of "data" looks wrong, but the * fine people in the X Consortium defined it this way @@ -124,9 +147,9 @@ void client_to_vdesk(Client *c, unsigned int vdesk) { if (valid_vdesk(vdesk)) { c->vdesk = vdesk; if (c->vdesk == c->screen->vdesk || c->vdesk == VDESK_FIXED) { - unhide(c, NO_RAISE); + client_show(c); } else { - hide(c); + client_hide(c); } ewmh_set_net_wm_desktop(c); select_client(current); diff --git a/events.c b/events.c index 7a6b364..601da98 100644 --- a/events.c +++ b/events.c @@ -129,8 +129,7 @@ static void handle_key_event(XKeyEvent *e) { send_wm_delete(c, e->state & altmask); break; case KEY_LOWER: case KEY_ALTLOWER: - XLowerWindow(dpy, c->parent); - ewmh_lower_client(c); + client_lower(c); break; case KEY_INFO: show_info(c, e->keycode); @@ -178,9 +177,7 @@ static void handle_button_event(XButtonEvent *e) { case Button2: sweep(c); break; case Button3: - XLowerWindow(dpy, c->parent); - ewmh_lower_client(c); - break; + client_lower(c); break; default: break; } } @@ -258,7 +255,8 @@ static void handle_map_request(XMapRequestEvent *e) { if (!is_fixed(c) && c->vdesk != c->screen->vdesk) switch_vdesk(c->screen, c->vdesk); #endif - unhide(c, RAISE); + client_show(c); + client_raise(c); } else { XWindowAttributes attr; XGetWindowAttributes(dpy, e->window, &attr); @@ -310,7 +308,7 @@ static void handle_property_change(XPropertyEvent *e) { && (is_fixed(c) || (c->vdesk == c->screen->vdesk)) #endif ) { - unhide(c, NO_RAISE); + client_show(c); } } LOG_LEAVE(); diff --git a/evilwm.h b/evilwm.h index 694f39e..1641d70 100644 --- a/evilwm.h +++ b/evilwm.h @@ -253,6 +253,10 @@ extern int wm_exit; /* client.c */ Client *find_client(Window w); +void client_hide(Client *c); +void client_show(Client *c); +void client_raise(Client *c); +void client_lower(Client *c); void gravitate_client(Client *c, int sign, int gravity); void select_client(Client *c); #ifdef VWM @@ -289,9 +293,7 @@ void moveresize(Client *c); void maximise_client(Client *c, int action, int hv); void show_info(Client *c, unsigned int keycode); void sweep(Client *c); -void unhide(Client *c, int raise_win); void next(void); -void hide(Client *c); #ifdef VWM void switch_vdesk(ScreenInfo *s, unsigned int v); #endif @@ -309,8 +311,6 @@ void ewmh_init_client(Client *c); void ewmh_deinit_client(Client *c); void ewmh_withdraw_client(Client *c); void ewmh_select_client(Client *c); -void ewmh_raise_client(Client *c); -void ewmh_lower_client(Client *c); void ewmh_set_net_client_list(ScreenInfo *s); void ewmh_set_net_client_list_stacking(ScreenInfo *s); #ifdef VWM diff --git a/ewmh.c b/ewmh.c index 2fdcc18..4ea6d74 100644 --- a/ewmh.c +++ b/ewmh.c @@ -248,16 +248,6 @@ void ewmh_select_client(Client *c) { clients_tab_order = list_to_head(clients_tab_order, c); } -void ewmh_raise_client(Client *c) { - clients_stacking_order = list_to_tail(clients_stacking_order, c); - ewmh_set_net_client_list_stacking(c->screen); -} - -void ewmh_lower_client(Client *c) { - clients_stacking_order = list_to_head(clients_stacking_order, c); - ewmh_set_net_client_list_stacking(c->screen); -} - void ewmh_set_net_client_list(ScreenInfo *s) { Window *windows = alloc_window_array(); struct list *iter; diff --git a/new.c b/new.c index 42d3576..aefda96 100644 --- a/new.c +++ b/new.c @@ -148,7 +148,8 @@ void make_new_client(Window w, ScreenInfo *s) { if (is_fixed(c) || c->vdesk == s->vdesk) #endif { - unhide(c, RAISE); + client_show(c); + client_raise(c); #ifndef MOUSE select_client(c); #ifdef WARP_POINTER diff --git a/screen.c b/screen.c index 0a86e46..45d9b28 100644 --- a/screen.c +++ b/screen.c @@ -121,8 +121,7 @@ void sweep(Client *c) { if (!grab_pointer(c->screen->root, MouseMask, resize_curs)) return; - XRaiseWindow(dpy, c->parent); - ewmh_raise_client(c); + client_raise(c); #ifdef INFOBANNER_MOVERESIZE create_info_window(c); #endif @@ -249,8 +248,7 @@ void drag(Client *c) { int old_cy = c->y; if (!grab_pointer(c->screen->root, MouseMask, move_curs)) return; - XRaiseWindow(dpy, c->parent); - ewmh_raise_client(c); + client_raise(c); get_mouse_position(&x1, &y1, c->screen->root); #ifdef INFOBANNER_MOVERESIZE create_info_window(c); @@ -308,8 +306,7 @@ void drag(Client *c) { #endif /* def MOUSE */ void moveresize(Client *c) { - XRaiseWindow(dpy, c->parent); - ewmh_raise_client(c); + client_raise(c); XMoveResizeWindow(dpy, c->parent, c->x - c->border, c->y - c->border, c->width, c->height); XMoveResizeWindow(dpy, c->window, 0, 0, c->width, c->height); @@ -372,27 +369,6 @@ void maximise_client(Client *c, int action, int hv) { discard_enter_events(); } -void hide(Client *c) { - /* This will generate an unmap event. Tell event handler - * to ignore it. */ - c->ignore_unmap++; - LOG_XENTER("XUnmapWindow(parent=%lx)", c->parent); - XUnmapWindow(dpy, c->parent); - LOG_XLEAVE(); - set_wm_state(c, IconicState); -} - -void unhide(Client *c, int raise_win) { - if (raise_win) { - XMapRaised(dpy, c->parent); - clients_stacking_order = list_to_tail(clients_stacking_order, c); - ewmh_set_net_client_list_stacking(c->screen); - } else { - XMapWindow(dpy, c->parent); - } - set_wm_state(c, NormalState); -} - void next(void) { struct list *newl = list_find(clients_tab_order, current); Client *newc = current; @@ -419,7 +395,8 @@ void next(void) { #endif if (!newc) return; - unhide(newc, RAISE); + client_show(newc); + client_raise(newc); select_client(newc); #ifdef WARP_POINTER setmouse(newc->window, newc->width + newc->border - 1, @@ -446,13 +423,13 @@ void switch_vdesk(ScreenInfo *s, unsigned int v) { if (c->screen != s) continue; if (c->vdesk == s->vdesk) { - hide(c); + client_hide(c); #ifdef DEBUG hidden++; #endif } else if (c->vdesk == v) { if (!c->is_dock || s->docks_visible) - unhide(c, NO_RAISE); + client_show(c); #ifdef DEBUG raised++; #endif @@ -477,11 +454,15 @@ void set_docks_visible(ScreenInfo *s, int is_visible) { if (c->is_dock) { if (is_visible) { #ifdef VWM - if (is_fixed(c) || (c->vdesk == s->vdesk)) + if (is_fixed(c) || (c->vdesk == s->vdesk)) { +#endif + client_show(c); + client_raise(c); +#ifdef VWM + } #endif - unhide(c, RAISE); } else { - hide(c); + client_hide(c); } } } -- 2.11.4.GIT