X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fscreen.c;h=49d3d22d46316c5b7a7d0f266010c84cf1cbd03b;hb=fb1696659672386bcfc0f753b67f9eeda74e93b9;hp=01acbfe22ff6f40570d21888eced5f8a527d120d;hpb=648c55b829e09c66222a9bbf08d10434622feae2;p=chaz%2Fopenbox diff --git a/openbox/screen.c b/openbox/screen.c index 01acbfe2..49d3d22d 100644 --- a/openbox/screen.c +++ b/openbox/screen.c @@ -1,5 +1,6 @@ #include "openbox.h" #include "prop.h" +#include "config.h" #include "screen.h" #include "client.h" #include "frame.h" @@ -20,7 +21,7 @@ SubstructureNotifyMask | SubstructureRedirectMask | \ ButtonPressMask | ButtonReleaseMask | ButtonMotionMask) -guint screen_num_desktops = 1; +guint screen_num_desktops = 0; guint screen_desktop = 0; Size screen_physical_size; gboolean screen_showing_desktop; @@ -29,6 +30,7 @@ GPtrArray *screen_desktop_names; static Rect *area = NULL; static Strut *strut = NULL; +static Window support_window = None; static void screen_update_area(); @@ -45,7 +47,6 @@ static int another_running(Display *d, XErrorEvent *e) gboolean screen_annex() { XErrorHandler old; - Window support; pid_t pid; int i, num_support; Atom *supported; @@ -68,14 +69,14 @@ gboolean screen_annex() PROP_SET32(ob_root, openbox_pid, cardinal, pid); /* create the netwm support window */ - support = XCreateSimpleWindow(ob_display, ob_root, 0, 0, 1, 1, 0, 0, 0); + support_window = XCreateSimpleWindow(ob_display, ob_root, 0,0,1,1,0,0,0); /* set supporting window */ - PROP_SET32(ob_root, net_supporting_wm_check, window, support); + PROP_SET32(ob_root, net_supporting_wm_check, window, support_window); /* set properties on the supporting window */ - PROP_SETS(support, net_wm_name, utf8, "Openbox"); - PROP_SET32(support, net_supporting_wm_check, window, support); + PROP_SETS(support_window, net_wm_name, utf8, "Openbox"); + PROP_SET32(support_window, net_supporting_wm_check, window,support_window); /* set the _NET_SUPPORTED_ATOMS hint */ num_support = 48; @@ -148,12 +149,24 @@ gboolean screen_annex() void screen_startup() { + GSList *it; + screen_desktop_names = g_ptr_array_new(); /* get the initial size */ screen_resize(); - screen_set_num_desktops(4); + /* set the names */ + for (it = config_desktops_names; it; it = it->next) + g_ptr_array_add(screen_desktop_names, it->data); /* dont strdup */ + PROP_SETSA(ob_root, net_desktop_names, utf8, screen_desktop_names); + g_ptr_array_set_size(screen_desktop_names, 0); /* rm the ptrs so they dont + get frees when we + update the desktop + names */ + screen_num_desktops = 0; + screen_set_num_desktops(config_desktops_num); + screen_desktop = 0; screen_set_desktop(0); /* don't start in showing-desktop mode */ @@ -166,6 +179,15 @@ void screen_startup() void screen_shutdown() { guint i; + + XSelectInput(ob_display, ob_root, NoEventMask); + + PROP_ERASE(ob_root, openbox_pid); /* we're not running here no more! */ + PROP_ERASE(ob_root, net_supported); /* not without us */ + PROP_ERASE(ob_root, net_showing_desktop); /* don't keep this mode */ + + XDestroyWindow(ob_display, support_window); + for (i = 0; i < screen_desktop_names->len; ++i) g_free(g_ptr_array_index(screen_desktop_names, i)); g_ptr_array_free(screen_desktop_names, TRUE); @@ -175,10 +197,10 @@ void screen_shutdown() void screen_resize() { - /* Set the _NET_DESKTOP_GEOMETRY hint */ /* XXX RandR support here? */ int geometry[2]; + /* Set the _NET_DESKTOP_GEOMETRY hint */ geometry[0] = WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen)); geometry[1] = HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen)); PROP_SET32A(ob_root, net_desktop_geometry, cardinal, geometry, 2); @@ -197,27 +219,9 @@ void screen_set_num_desktops(guint num) { guint i, old; gulong *viewport; - + GList *it; + g_assert(num > 0); - - /* move windows on desktops that will no longer exist! */ - /* XXX - std::list::iterator it, end = clients.end(); - for (it = clients.begin(); it != end; ++it) { - unsigned int d = (*it)->desktop(); - if (d >= num && d != 0xffffffff) { - XEvent ce; - ce.xclient.type = ClientMessage; - ce.xclient.message_type = otk::Property::atoms.net_wm_desktop; - ce.xclient.display = **otk::display; - ce.xclient.window = (*it)->window(); - ce.xclient.format = 32; - ce.xclient.data.l[0] = num - 1; - XSendEvent(**otk::display, _info->rootWindow(), false, - SubstructureNotifyMask | SubstructureRedirectMask, &ce); - } - } - */ old = screen_num_desktops; screen_num_desktops = num; @@ -247,6 +251,13 @@ void screen_set_num_desktops(guint num) for (i = old; i < num; ++i) focus_order[i] = NULL; + /* move windows on desktops that will no longer exist! */ + for (it = client_list; it != NULL; it = it->next) { + Client *c = it->data; + if (c->desktop >= num) + client_set_desktop(c, num - 1, FALSE); + } + dispatch_ob(Event_Ob_NumDesktops, num, old); /* change our desktop if we're on one that no longer exists! */ @@ -258,23 +269,19 @@ void screen_set_desktop(guint num) { GList *it; guint old; + XEvent e; g_assert(num < screen_num_desktops); - g_message("Moving to desktop %u", num); - old = screen_desktop; screen_desktop = num; PROP_SET32(ob_root, net_current_desktop, cardinal, num); if (old == num) return; - /* hide windows from bottom to top */ - for (it = g_list_last(stacking_list); it != NULL; it = it->prev) { - Client *c = it->data; - if (c->frame->visible && !client_should_show(c)) - engine_frame_hide(c->frame); - } + g_message("Moving to desktop %d", num+1); + + /* show windows before hiding the rest to lessen the enter/leave events */ /* show windows from top to bottom */ for (it = stacking_list; it != NULL; it = it->next) { @@ -283,6 +290,19 @@ void screen_set_desktop(guint num) engine_frame_show(c->frame); } + /* hide windows from bottom to top */ + for (it = g_list_last(stacking_list); it != NULL; it = it->prev) { + Client *c = it->data; + if (c->frame->visible && !client_should_show(c)) + engine_frame_hide(c->frame); + } + + /* focus the last focused window on the desktop, and ignore enter events + from the switch so it doesnt mess with the focus */ + XSync(ob_display, FALSE); + while (XCheckTypedEvent(ob_display, EnterNotify, &e)); + focus_fallback(Fallback_Desktop); + dispatch_ob(Event_Ob_Desktop, num, old); } @@ -366,24 +386,16 @@ void screen_update_desktop_names() void screen_show_desktop(gboolean show) { GList *it; - static Window saved_focus = 0; if (show == screen_showing_desktop) return; /* no change */ - /* save the window focus, and restore it when leaving the show-desktop - mode */ - if (show && focus_client) - saved_focus = focus_client->window; - screen_showing_desktop = show; if (show) { /* bottom to top */ for (it = g_list_last(stacking_list); it != NULL; it = it->prev) { Client *client = it->data; - if (client->type == Type_Desktop) - client_focus(client); - else if (client->frame->visible && !client_should_show(client)) + if (client->frame->visible && !client_should_show(client)) engine_frame_hide(client->frame); } } else { @@ -395,15 +407,6 @@ void screen_show_desktop(gboolean show) } } - if (!show) { - Client *f = focus_client; - if (!f || f->type == Type_Desktop) { - Client *c = g_hash_table_lookup(client_map, - (gpointer)saved_focus); - if (c) client_focus(c); - } - } - show = !!show; /* make it boolean */ PROP_SET32(ob_root, net_showing_desktop, cardinal, show); @@ -412,14 +415,16 @@ void screen_show_desktop(gboolean show) void screen_install_colormap(Client *client, gboolean install) { + XWindowAttributes wa; + if (client == NULL) { if (install) XInstallColormap(ob_display, render_colormap); else XUninstallColormap(ob_display, render_colormap); } else { - XWindowAttributes wa; - if (XGetWindowAttributes(ob_display, client->window, &wa)) { + if (XGetWindowAttributes(ob_display, client->window, &wa) && + wa.colormap != None) { if (install) XInstallColormap(ob_display, wa.colormap); else @@ -430,14 +435,13 @@ void screen_install_colormap(Client *client, gboolean install) void screen_update_struts() { - GSList *it; + GList *it; guint i; - if (strut != NULL) - g_free(strut); + g_free(strut); strut = g_new0(Strut, screen_num_desktops + 1); - for (it = client_list; it; it = it->next) { + for (it = client_list; it != NULL; it = it->next) { Client *c = it->data; if (c->iconic) continue; /* these dont count in the strut */ @@ -458,9 +462,8 @@ static void screen_update_area() { guint i; gulong *dims; - - if (area != NULL) - g_free(area); + + g_free(area); area = g_new0(Rect, screen_num_desktops + 1); dims = g_new(unsigned long, 4 * screen_num_desktops); @@ -504,7 +507,7 @@ static void screen_update_area() */ if (!RECT_EQUAL(old_area, area[i])) { /* the area has changed, adjust all the maximized windows */ - GSList *it; + GList *it; for (it = client_list; it; it = it->next) { Client *c = it->data; if (i < screen_num_desktops) {