From 47ee7454252366bc1351e419849f391e861c7bb5 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 13 Jan 2008 16:30:43 +0100 Subject: [PATCH] rewrite client_manage() --- client.c | 104 ++++++++++++++++++++++++++------------------------------------- event.c | 5 +-- tag.c | 43 ++++++++------------------ tag.h | 2 +- 4 files changed, 58 insertions(+), 96 deletions(-) diff --git a/client.c b/client.c index 3735fadf..9f6c65d7 100644 --- a/client.c +++ b/client.c @@ -230,15 +230,13 @@ client_manage(Window w, XWindowAttributes *wa, int screen) Window trans; Bool rettrans; XWindowChanges wc; - Area area, darea; Tag *tag; Rule *rule; int phys_screen = get_phys_screen(screen); - area = get_screen_area(screen, NULL, NULL); - c = p_new(Client, 1); + /* Initial values */ c->win = w; c->geometry.x = c->f_geometry.x = c->m_geometry.x = wa->x; c->geometry.y = c->f_geometry.y = c->m_geometry.y = wa->y; @@ -247,56 +245,54 @@ client_manage(Window w, XWindowAttributes *wa, int screen) c->oldborder = wa->border_width; c->newcomer = True; + c->border = globalconf.screens[screen].borderpx; c->screen = get_screen_bycoord(c->geometry.x, c->geometry.y); - move_client_to_screen(c, screen, True); + /* Set windows borders */ + wc.border_width = c->border; + XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc); + XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel); + /* propagates border_width, if size doesn't change */ + window_configure(c->win, c->geometry, c->border); /* update window title */ client_updatetitle(c); - if(c->geometry.width == area.width && c->geometry.height == area.height) - c->border = wa->border_width; - else - c->border = globalconf.screens[screen].borderpx; + /* update hints */ + client_updatesizehints(c); + client_updatewmhints(c); + /* First check clients hints */ ewmh_check_client_hints(c); + /* loadprops or apply rules if no props */ if(!client_loadprops(c, screen)) - tag_client_with_rules(c); - - /* if window request fullscreen mode */ - if(c->geometry.width == area.width && c->geometry.height == area.height) - { - c->geometry.x = area.x; - c->geometry.y = area.y; - } - else { - darea = get_display_area(phys_screen, - globalconf.screens[screen].statusbar, - &globalconf.screens[screen].padding); - - if(c->geometry.x + c->geometry.width + 2 * c->border > darea.x + darea.width) - c->geometry.x = c->f_geometry.x = darea.x + darea.width - c->geometry.width - 2 * c->border; - if(c->geometry.y + c->geometry.height + 2 * c->border > darea.y + darea.height) - c->geometry.y = c->f_geometry.y = darea.y + darea.height - c->geometry.height - 2 * c->border; - if(c->geometry.x < darea.x) - c->geometry.x = c->f_geometry.x = darea.x; - if(c->geometry.y < darea.y) - c->geometry.y = c->f_geometry.y = darea.y; - } - - /* XXX if this necessary ? */ - /* set borders */ - wc.border_width = c->border; - XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc); - XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel); - /* propagates border_width, if size doesn't change */ - window_configure(c->win, c->geometry, c->border); + /* Get the client's rule */ + if((rule = rule_matching_client(c))) + { + if(rule->screen != RULE_NOSCREEN) + move_client_to_screen(c, rule->screen, True); + else + move_client_to_screen(c, screen, True); + if(!tag_client_with_rule(c, rule)) + tag_client_with_current_selected(c); + } + else + move_client_to_screen(c, screen, True); + /* check for transient and set tags like its parent, + * XGetTransientForHint returns 1 on success + */ + if((rettrans = XGetTransientForHint(globalconf.display, w, &trans)) + && (t = get_client_bywin(globalconf.clients, trans))) + for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next) + if(is_client_tagged(t, tag)) + tag_client(c, tag); - /* update hints */ - client_updatesizehints(c); - client_updatewmhints(c); + /* should be floating if transsient or fixed */ + if(!c->isfloating) + c->isfloating = rettrans || c->isfixed; + } XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask); @@ -307,22 +303,6 @@ client_manage(Window w, XWindowAttributes *wa, int screen) window_setshape(phys_screen, c->win); } - /* grab buttons */ - window_grabbuttons(phys_screen, c->win, False, True); - - /* check for transient and set tags like its parent, - * XGetTransientForHint returns 1 on success - */ - if((rettrans = XGetTransientForHint(globalconf.display, w, &trans)) - && (t = get_client_bywin(globalconf.clients, trans))) - for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next) - if(is_client_tagged(t, tag)) - tag_client(c, tag); - - /* should be floating if transsient or fixed */ - if(!c->isfloating) - c->isfloating = rettrans || c->isfixed; - /* save new props */ client_saveprops(c); @@ -334,16 +314,16 @@ client_manage(Window w, XWindowAttributes *wa, int screen) else client_list_append(&globalconf.clients, c); - ewmh_update_net_client_list(phys_screen); + /* focus ? */ + if(globalconf.screens[c->screen].new_get_focus) + focus(c, True, c->screen); /* some windows require this */ XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y, c->geometry.width, c->geometry.height); - - if(globalconf.screens[c->screen].new_get_focus) - focus(c, True, screen); - + widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); + ewmh_update_net_client_list(phys_screen); /* rearrange to display new window */ arrange(c->screen); diff --git a/event.c b/event.c index 116083a7..20b60e6e 100644 --- a/event.c +++ b/event.c @@ -35,9 +35,10 @@ #include "ewmh.h" #include "client.h" #include "widget.h" +#include "xutil.h" +#include "rules.h" #include "layouts/tile.h" #include "layouts/floating.h" -#include "xutil.h" extern AwesomeConf globalconf; @@ -163,7 +164,7 @@ handle_event_configurerequest(XEvent * e) client_resize(c, geometry, False); - tag_client_with_rules(c); + tag_client_with_rule(c, rule_matching_client(c)); if(old_screen != c->screen) { diff --git a/tag.c b/tag.c index ef60d9c1..f6dd53af 100644 --- a/tag.c +++ b/tag.c @@ -93,46 +93,27 @@ tag_client_with_current_selected(Client *c) untag_client(c, tag); } -void -tag_client_with_rules(Client *c) +Bool +tag_client_with_rule(Client *c, Rule *r) { - Rule *r; Tag *tag; Bool matched = False; - if((r = rule_matching_client(c))) - { - switch(r->isfloating) + if(!r) + return False; + + for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next) + if(tag_match_rule(tag, r)) { - case Tile: - c->isfloating = False; - break; - case Float: - c->isfloating = True; - client_resize(c, c->f_geometry, False); - break; - default: - break; + matched = True; + tag_client(c, tag); } + else + untag_client(c, tag); - if(r->screen != RULE_NOSCREEN && r->screen != c->screen) - move_client_to_screen(c, r->screen, True); - - for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next) - if(tag_match_rule(tag, r)) - { - matched = True; - tag_client(c, tag); - } - else - untag_client(c, tag); - - if(!matched) - tag_client_with_current_selected(c); - } + return matched; } - Tag ** get_current_tags(int screen) { diff --git a/tag.h b/tag.h index 60d6d695..48c95e91 100644 --- a/tag.h +++ b/tag.h @@ -31,8 +31,8 @@ Tag ** get_current_tags(int ); void tag_client(Client *, Tag *); void untag_client(Client *, Tag *); Bool is_client_tagged(Client *, Tag *); +Bool tag_client_with_rule(Client *, Rule *r); void tag_client_with_current_selected(Client *); -void tag_client_with_rules(Client *); void tag_view_only_byindex(int, int); Uicb uicb_client_tag; -- 2.11.4.GIT