X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fscreen.c;h=76ad1f274803e65f69997a01efd9a14341bc8098;hb=24f6b59fe36e06d06bd1139a99e08cb6e06d6682;hp=04a3b452be033989b99c5e8c614a965d7381e592;hpb=c12d09bde85e40fdfbb36225a1b596b5f27c2335;p=chaz%2Fopenbox diff --git a/openbox/screen.c b/openbox/screen.c index 04a3b452..76ad1f27 100644 --- a/openbox/screen.c +++ b/openbox/screen.c @@ -52,22 +52,24 @@ ButtonPressMask | ButtonReleaseMask) static gboolean screen_validate_layout(ObDesktopLayout *l); -static gboolean replace_wm(); -static void screen_tell_ksplash(); -static void screen_fallback_focus(); - -guint screen_num_desktops; -guint screen_num_monitors; -guint screen_desktop; -guint screen_last_desktop; -Size screen_physical_size; -gboolean screen_showing_desktop; +static gboolean replace_wm(void); +static void screen_tell_ksplash(void); +static void screen_fallback_focus(void); + +guint screen_num_desktops; +guint screen_num_monitors; +guint screen_desktop; +guint screen_last_desktop; +gboolean screen_showing_desktop; ObDesktopLayout screen_desktop_layout; -gchar **screen_desktop_names; -Window screen_support_win; -Time screen_desktop_user_time = CurrentTime; - -/*! An array of desktops, holding array of areas per monitor */ +gchar **screen_desktop_names; +Window screen_support_win; +Time screen_desktop_user_time = CurrentTime; + +static Size screen_physical_size; +static guint screen_old_desktop; +static gboolean screen_desktop_timeout = TRUE; +/*! An array of desktops, holding an array of areas per monitor */ static Rect *monitor_area = NULL; /*! An array of desktops, holding an array of struts */ static GSList *struts_top = NULL; @@ -77,7 +79,11 @@ static GSList *struts_bottom = NULL; static ObPagerPopup *desktop_popup; -static gboolean replace_wm() +/*! The number of microseconds that you need to be on a desktop before it will + replace the remembered "last desktop" */ +#define REMEMBER_LAST_DESKTOP_TIME 750000 + +static gboolean replace_wm(void) { gchar *wm_sn; Atom wm_sn_atom; @@ -149,7 +155,7 @@ static gboolean replace_wm() return TRUE; } -gboolean screen_annex() +gboolean screen_annex(void) { XSetWindowAttributes attrib; pid_t pid; @@ -283,6 +289,8 @@ gboolean screen_annex() supported[i++] = prop_atoms.net_wm_sync_request; supported[i++] = prop_atoms.net_wm_sync_request_counter; #endif + supported[i++] = prop_atoms.net_wm_pid; + supported[i++] = prop_atoms.net_wm_ping; supported[i++] = prop_atoms.kde_wm_change_state; supported[i++] = prop_atoms.kde_net_wm_frame_strut; @@ -292,7 +300,11 @@ gboolean screen_annex() supported[i++] = prop_atoms.ob_wm_state_undecorated; supported[i++] = prop_atoms.openbox_pid; supported[i++] = prop_atoms.ob_theme; + supported[i++] = prop_atoms.ob_config_file; supported[i++] = prop_atoms.ob_control; + supported[i++] = prop_atoms.ob_role; + supported[i++] = prop_atoms.ob_name; + supported[i++] = prop_atoms.ob_class; g_assert(i == num_support); PROP_SETA32(RootWindow(ob_display, ob_screen), @@ -304,7 +316,7 @@ gboolean screen_annex() return TRUE; } -static void screen_tell_ksplash() +static void screen_tell_ksplash(void) { XEvent e; char **argv; @@ -331,7 +343,7 @@ static void screen_tell_ksplash() e.xclient.display = ob_display; e.xclient.window = RootWindow(ob_display, ob_screen); e.xclient.message_type = - XInternAtom(ob_display, "_KDE_SPLASH_PROGRESS", False ); + XInternAtom(ob_display, "_KDE_SPLASH_PROGRESS", False); e.xclient.format = 8; strcpy(e.xclient.data.b, "wm started"); XSendEvent(ob_display, RootWindow(ob_display, ob_screen), @@ -394,7 +406,17 @@ void screen_startup(gboolean reconfig) screen_num_desktops = 0; if (PROP_GET32(RootWindow(ob_display, ob_screen), net_number_of_desktops, cardinal, &d)) + { + if (d != config_desktops_num) { + /* TRANSLATORS: If you need to specify a different order of the + arguments, you can use %1$d for the first one and %2$d for the + second one. For example, + "The current session has %2$d desktops, but Openbox is configured for %1$d ..." */ + g_warning(ngettext("Openbox is configured for %d desktop, but the current session has %d. Overriding the Openbox configuration.", "Openbox is configured for %d desktops, but the current session has %d. Overriding the Openbox configuration.", config_desktops_num), + config_desktops_num, d); + } screen_set_num_desktops(d); + } /* restore from session if possible */ else if (session_num_desktops) screen_set_num_desktops(session_num_desktops); @@ -453,7 +475,7 @@ void screen_shutdown(gboolean reconfig) screen_desktop_names = NULL; } -void screen_resize() +void screen_resize(void) { static gint oldw = 0, oldh = 0; gint w, h; @@ -473,7 +495,7 @@ void screen_resize() PROP_SETA32(RootWindow(ob_display, ob_screen), net_desktop_geometry, cardinal, geometry, 2); - if (ob_state() == OB_STATE_STARTING) + if (ob_state() != OB_STATE_RUNNING) return; screen_update_areas(); @@ -523,12 +545,13 @@ void screen_set_num_desktops(guint num) stacking_raise(CLIENT_AS_WINDOW(c)); } } + g_list_free(stacking_copy); /* change our struts/area to match (after moving windows) */ screen_update_areas(); /* may be some unnamed desktops that we need to fill in with names - (after updating the areas so the popup can resize) */ + (after updating the areas so the popup can resize) */ screen_update_desktop_names(); /* change our desktop if we're on one that no longer exists! */ @@ -536,7 +559,7 @@ void screen_set_num_desktops(guint num) screen_set_desktop(num - 1, TRUE); } -static void screen_fallback_focus() +static void screen_fallback_focus(void) { ObClient *c; gboolean allow_omni; @@ -577,26 +600,101 @@ static void screen_fallback_focus() } } +static gboolean last_desktop_func(gpointer data) +{ + screen_desktop_timeout = TRUE; + return FALSE; +} + void screen_set_desktop(guint num, gboolean dofocus) { GList *it; - guint old; + guint previous; gulong ignore_start; g_assert(num < screen_num_desktops); - old = screen_desktop; + previous = screen_desktop; screen_desktop = num; - if (old == num) return; + if (previous == num) return; PROP_SET32(RootWindow(ob_display, ob_screen), net_current_desktop, cardinal, num); - screen_last_desktop = old; + /* This whole thing decides when/how to save the screen_last_desktop so + that it can be restored later if you want */ + if (screen_desktop_timeout) { + /* If screen_desktop_timeout is true, then we've been on this desktop + long enough and we can save it as the last desktop. */ + + if (screen_last_desktop == previous) + /* this is the startup state only */ + screen_old_desktop = screen_desktop; + else { + /* save the "last desktop" as the "old desktop" */ + screen_old_desktop = screen_last_desktop; + /* save the desktop we're coming from as the "last desktop" */ + screen_last_desktop = previous; + } + } + else { + /* If screen_desktop_timeout is false, then we just got to this desktop + and we are moving away again. */ + + if (screen_desktop == screen_last_desktop) { + /* If we are moving to the "last desktop" .. */ + if (previous == screen_old_desktop) { + /* .. from the "old desktop", change the last desktop to + be where we are coming from */ + screen_last_desktop = screen_old_desktop; + } + else if (screen_last_desktop == screen_old_desktop) { + /* .. and also to the "old desktop", change the "last + desktop" to be where we are coming from */ + screen_last_desktop = previous; + } + else { + /* .. from some other desktop, then set the "last desktop" to + be the saved "old desktop", i.e. where we were before the + "last desktop" */ + screen_last_desktop = screen_old_desktop; + } + } + else { + /* If we are moving to any desktop besides the "last desktop".. + (this is the normal case) */ + if (screen_desktop == screen_old_desktop) { + /* If moving to the "old desktop", which is not the + "last desktop", don't save anything */ + } + else if (previous == screen_old_desktop) { + /* If moving from the "old desktop", and not to the + "last desktop", don't save anything */ + } + else if (screen_last_desktop == screen_old_desktop) { + /* If the "last desktop" is the same as "old desktop" and + you're not moving to the "last desktop" then save where + we're coming from as the "last desktop" */ + screen_last_desktop = previous; + } + else { + /* If the "last desktop" is different from the "old desktop" + and you're not moving to the "last desktop", then don't save + anything */ + } + } + } + screen_desktop_timeout = FALSE; + ob_main_loop_timeout_remove(ob_main_loop, last_desktop_func); + ob_main_loop_timeout_add(ob_main_loop, REMEMBER_LAST_DESKTOP_TIME, + last_desktop_func, NULL, NULL, NULL); ob_debug("Moving to desktop %d\n", num+1); + if (ob_state() == OB_STATE_RUNNING) + screen_show_desktop_popup(screen_desktop); + /* ignore enter events caused by the move */ ignore_start = event_start_ignore_all_enters(); @@ -619,7 +717,15 @@ void screen_set_desktop(guint num, gboolean dofocus) for (it = g_list_last(stacking_list); it; it = g_list_previous(it)) { if (WINDOW_IS_CLIENT(it->data)) { ObClient *c = it->data; - client_hide(c); + if (client_hide(c) && c == focus_client) { + /* c was focused and we didn't do fallback clearly so make sure + openbox doesnt still consider the window focused. + this happens when using NextWindow with allDesktops, since + it doesnt want to move focus on desktop change, but the + focus is not going to stay with the current window, which + has now disappeared */ + focus_set_client(NULL); + } } } @@ -627,9 +733,6 @@ void screen_set_desktop(guint num, gboolean dofocus) if (event_curtime != CurrentTime) screen_desktop_user_time = event_curtime; - - if (ob_state() == OB_STATE_RUNNING) - screen_show_desktop_popup(screen_desktop); } void screen_add_desktop(gboolean current) @@ -707,6 +810,7 @@ void screen_remove_desktop(gboolean current) } } } + g_list_free(stacking_copy); /* fallback focus like we're changing desktops */ if (screen_desktop < screen_num_desktops - 1) { @@ -840,7 +944,7 @@ void screen_show_desktop_popup(guint d) /* 0 means don't show the popup */ if (!config_desktop_popup_time) return; - a = screen_physical_area_active(); + a = screen_physical_area_primary(FALSE); pager_popup_position(desktop_popup, CenterGravity, a->x + a->width / 2, a->y + a->height / 2); pager_popup_icon_size_multiplier(desktop_popup, @@ -858,7 +962,7 @@ void screen_show_desktop_popup(guint d) g_free(a); } -void screen_hide_desktop_popup() +void screen_hide_desktop_popup(void) { ob_main_loop_timeout_remove(ob_main_loop, hide_desktop_popup_func); pager_popup_hide(desktop_popup); @@ -1007,7 +1111,7 @@ static gboolean screen_validate_layout(ObDesktopLayout *l) return TRUE; } -void screen_update_layout() +void screen_update_layout(void) { ObDesktopLayout l; @@ -1056,7 +1160,7 @@ void screen_update_layout() } } -void screen_update_desktop_names() +void screen_update_desktop_names(void) { guint i; @@ -1180,19 +1284,6 @@ void screen_install_colormap(ObClient *client, gboolean install) } } -#define STRUT_LEFT_ON_MONITOR(s, i) \ - (RANGES_INTERSECT(s->left_start, s->left_end - s->left_start + 1, \ - monitor_area[i].y, monitor_area[i].height)) -#define STRUT_RIGHT_ON_MONITOR(s, i) \ - (RANGES_INTERSECT(s->right_start, s->right_end - s->right_start + 1, \ - monitor_area[i].y, monitor_area[i].height)) -#define STRUT_TOP_ON_MONITOR(s, i) \ - (RANGES_INTERSECT(s->top_start, s->top_end - s->top_start + 1, \ - monitor_area[i].x, monitor_area[i].width)) -#define STRUT_BOTTOM_ON_MONITOR(s, i) \ - (RANGES_INTERSECT(s->bottom_start, s->bottom_end - s->bottom_start + 1, \ - monitor_area[i].x, monitor_area[i].width)) - typedef struct { guint desktop; StrutPartial *strut; @@ -1218,12 +1309,11 @@ typedef struct { } \ } -void screen_update_areas() +void screen_update_areas(void) { - guint i, j; + guint i; gulong *dims; GList *it; - GSList *sit; g_free(monitor_area); extensions_xinerama_screens(&monitor_area, &screen_num_monitors); @@ -1238,8 +1328,6 @@ void screen_update_areas() config_margins.right_start = RECT_TOP(monitor_area[screen_num_monitors]); config_margins.right_end = RECT_BOTTOM(monitor_area[screen_num_monitors]); - dims = g_new(gulong, 4 * screen_num_desktops * screen_num_monitors); - RESET_STRUT_LIST(struts_left); RESET_STRUT_LIST(struts_top); RESET_STRUT_LIST(struts_right); @@ -1284,57 +1372,17 @@ void screen_update_areas() VALIDATE_STRUTS(struts_bottom, bottom, monitor_area[screen_num_monitors].height / 2); - /* set up the work areas to be full screen */ - for (i = 0; i < screen_num_monitors; ++i) - for (j = 0; j < screen_num_desktops; ++j) { - dims[(i * screen_num_desktops + j) * 4+0] = monitor_area[i].x; - dims[(i * screen_num_desktops + j) * 4+1] = monitor_area[i].y; - dims[(i * screen_num_desktops + j) * 4+2] = monitor_area[i].width; - dims[(i * screen_num_desktops + j) * 4+3] = monitor_area[i].height; - } - - /* calculate the work areas from the struts */ - for (i = 0; i < screen_num_monitors; ++i) - for (j = 0; j < screen_num_desktops; ++j) { - gint l = 0, r = 0, t = 0, b = 0; - - /* only add the strut to the area if it touches the monitor */ - - for (sit = struts_left; sit; sit = g_slist_next(sit)) { - ObScreenStrut *s = sit->data; - if ((s->desktop == j || s->desktop == DESKTOP_ALL) && - STRUT_LEFT_ON_MONITOR(s->strut, i)) - l = MAX(l, s->strut->left); - } - for (sit = struts_top; sit; sit = g_slist_next(sit)) { - ObScreenStrut *s = sit->data; - if ((s->desktop == j || s->desktop == DESKTOP_ALL) && - STRUT_TOP_ON_MONITOR(s->strut, i)) - t = MAX(t, s->strut->top); - } - for (sit = struts_right; sit; sit = g_slist_next(sit)) { - ObScreenStrut *s = sit->data; - if ((s->desktop == j || s->desktop == DESKTOP_ALL) && - STRUT_RIGHT_ON_MONITOR(s->strut, i)) - r = MAX(r, s->strut->right); - } - for (sit = struts_bottom; sit; sit = g_slist_next(sit)) { - ObScreenStrut *s = sit->data; - if ((s->desktop == j || s->desktop == DESKTOP_ALL) && - STRUT_BOTTOM_ON_MONITOR(s->strut, i)) - b = MAX(b, s->strut->bottom); - } - - /* based on these margins, set the work area for the - monitor/desktop */ - dims[(i * screen_num_desktops + j) * 4 + 0] += l; - dims[(i * screen_num_desktops + j) * 4 + 1] += t; - dims[(i * screen_num_desktops + j) * 4 + 2] -= l + r; - dims[(i * screen_num_desktops + j) * 4 + 3] -= t + b; - } + dims = g_new(gulong, 4 * screen_num_desktops); + for (i = 0; i < screen_num_desktops; ++i) { + Rect *area = screen_area(i, SCREEN_AREA_ALL_MONITORS, NULL); + dims[i*4+0] = area->x; + dims[i*4+1] = area->y; + dims[i*4+2] = area->width; + dims[i*4+3] = area->height; + g_free(area); + } - /* all the work areas are not used here, only the ones for the first - monitor are */ + /* set the legacy workarea hint to the union of all the monitors */ PROP_SETA32(RootWindow(ob_display, ob_screen), net_workarea, cardinal, dims, 4 * screen_num_desktops); @@ -1465,28 +1513,32 @@ Rect* screen_area(guint desktop, guint head, Rect *search) if ((s->desktop == d || s->desktop == DESKTOP_ALL) && STRUT_LEFT_IN_SEARCH(s->strut, search) && !STRUT_LEFT_IGNORE(s->strut, us, search)) - l = MAX(l, al + s->strut->left); + l = MAX(l, RECT_LEFT(monitor_area[screen_num_monitors]) + + s->strut->left); } for (it = struts_top; it; it = g_slist_next(it)) { ObScreenStrut *s = it->data; if ((s->desktop == d || s->desktop == DESKTOP_ALL) && STRUT_TOP_IN_SEARCH(s->strut, search) && !STRUT_TOP_IGNORE(s->strut, us, search)) - t = MAX(t, at + s->strut->top); + t = MAX(t, RECT_TOP(monitor_area[screen_num_monitors]) + + s->strut->top); } for (it = struts_right; it; it = g_slist_next(it)) { ObScreenStrut *s = it->data; if ((s->desktop == d || s->desktop == DESKTOP_ALL) && STRUT_RIGHT_IN_SEARCH(s->strut, search) && !STRUT_RIGHT_IGNORE(s->strut, us, search)) - r = MIN(r, ar - s->strut->right); + r = MIN(r, RECT_RIGHT(monitor_area[screen_num_monitors]) + - s->strut->right); } for (it = struts_bottom; it; it = g_slist_next(it)) { ObScreenStrut *s = it->data; if ((s->desktop == d || s->desktop == DESKTOP_ALL) && STRUT_BOTTOM_IN_SEARCH(s->strut, search) && !STRUT_BOTTOM_IGNORE(s->strut, us, search)) - b = MIN(b, ab - s->strut->bottom); + b = MIN(b, RECT_BOTTOM(monitor_area[screen_num_monitors]) + - s->strut->bottom); } /* limit to this monitor */ @@ -1510,7 +1562,7 @@ Rect* screen_area(guint desktop, guint head, Rect *search) guint screen_find_monitor(Rect *search) { guint i; - guint most = 0; + guint most = screen_num_monitors; guint mostv = 0; for (i = 0; i < screen_num_monitors; ++i) { @@ -1532,7 +1584,7 @@ guint screen_find_monitor(Rect *search) return most; } -Rect* screen_physical_area_all_monitors() +Rect* screen_physical_area_all_monitors(void) { return screen_physical_area_monitor(screen_num_monitors); } @@ -1554,27 +1606,43 @@ gboolean screen_physical_area_monitor_contains(guint head, Rect *search) return RECT_INTERSECTS_RECT(monitor_area[head], *search); } -Rect* screen_physical_area_active() +guint screen_monitor_active(void) { - Rect *a; - gint x, y; - if (moveresize_client) - a = screen_physical_area_monitor(client_monitor(focus_client)); + return client_monitor(moveresize_client); else if (focus_client) - a = screen_physical_area_monitor(client_monitor(focus_client)); - else { - Rect mon; - if (screen_pointer_pos(&x, &y)) - RECT_SET(mon, x, y, 1, 1); + return client_monitor(focus_client); + else + return screen_monitor_pointer(); +} + +Rect* screen_physical_area_active(void) +{ + return screen_physical_area_monitor(screen_monitor_active()); +} + +guint screen_monitor_primary(gboolean fixed) +{ + if (config_primary_monitor_index > 0) { + if (config_primary_monitor_index-1 < screen_num_monitors) + return config_primary_monitor_index - 1; else - RECT_SET(mon, 0, 0, 1, 1); - a = screen_physical_area_monitor(screen_find_monitor(&mon)); + return 0; } - return a; + else if (fixed) + return 0; + else if (config_primary_monitor == OB_PLACE_MONITOR_ACTIVE) + return screen_monitor_active(); + else /* config_primary_monitor == OB_PLACE_MONITOR_MOUSE */ + return screen_monitor_pointer(); } -void screen_set_root_cursor() +Rect *screen_physical_area_primary(gboolean fixed) +{ + return screen_physical_area_monitor(screen_monitor_primary(fixed)); +} + +void screen_set_root_cursor(void) { if (sn_app_starting()) XDefineCursor(ob_display, RootWindow(ob_display, ob_screen), @@ -1584,6 +1652,21 @@ void screen_set_root_cursor() ob_cursor(OB_CURSOR_POINTER)); } +guint screen_find_monitor_point(guint x, guint y) +{ + Rect mon; + RECT_SET(mon, x, y, 1, 1); + return screen_find_monitor(&mon); +} + +guint screen_monitor_pointer() +{ + gint x, y; + if (!screen_pointer_pos(&x, &y)) + x = y = 0; + return screen_find_monitor_point(x, y); +} + gboolean screen_pointer_pos(gint *x, gint *y) { Window w;