From 6238f61c0f86f2ebacda6428acb77a197e3b587c Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Fri, 11 Oct 2019 17:51:54 +0200 Subject: [PATCH] Bring back "Show desktop switch popup on every monitor" This time remembering that screen_num_monitors can change. --- openbox/screen.c | 97 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 26 deletions(-) diff --git a/openbox/screen.c b/openbox/screen.c index 2aa2c56d..342a6db6 100644 --- a/openbox/screen.c +++ b/openbox/screen.c @@ -78,7 +78,7 @@ static GSList *struts_left = NULL; static GSList *struts_right = NULL; static GSList *struts_bottom = NULL; -static ObPagerPopup *desktop_popup; +static ObPagerPopup **desktop_popup; static guint desktop_popup_timer = 0; static gboolean desktop_popup_perm; @@ -320,22 +320,39 @@ gboolean screen_annex(void) return TRUE; } +static void desktop_popup_new() +{ + guint i; + desktop_popup = g_new(ObPagerPopup*, screen_num_monitors); + for (i = 0; i < screen_num_monitors; i++) { + desktop_popup[i] = pager_popup_new(); + desktop_popup[i]->popup->a_text->texture[0].data.text.font = ob_rr_theme->menu_title_font; + pager_popup_height(desktop_popup[i], POPUP_HEIGHT); + + /* update the pager popup's width */ + if (screen_desktop_names) + pager_popup_text_width_to_strings(desktop_popup[i], + screen_desktop_names, + screen_num_desktops); + } + +} + void screen_startup(gboolean reconfig) { gchar **names = NULL; guint32 d; gboolean namesexist = FALSE; - desktop_popup = pager_popup_new(); desktop_popup_perm = FALSE; - pager_popup_height(desktop_popup, POPUP_HEIGHT); if (reconfig) { - /* update the pager popup's width */ - pager_popup_text_width_to_strings(desktop_popup, - screen_desktop_names, - screen_num_desktops); + desktop_popup_new(); return; + } else { + if (desktop_popup) + ob_debug("desktop_popup wasn't NULL when expected %x", desktop_popup); + desktop_popup = NULL; } /* get the initial size */ @@ -426,9 +443,19 @@ void screen_startup(gboolean reconfig) screen_update_layout(); } +static void desktop_popup_free(guint n) +{ + guint i; + for (i = 0; i < n; i++) { + pager_popup_free(desktop_popup[i]); + } + g_free(desktop_popup); + desktop_popup = NULL; +} + void screen_shutdown(gboolean reconfig) { - pager_popup_free(desktop_popup); + desktop_popup_free(screen_num_monitors); if (reconfig) return; @@ -907,30 +934,37 @@ static guint translate_row_col(guint r, guint c) static gboolean hide_desktop_popup_func(gpointer data) { - pager_popup_hide(desktop_popup); + guint i; + desktop_popup_timer = 0; + + for (i = 0; i < screen_num_monitors; i++) { + pager_popup_hide(desktop_popup[i]); + } return FALSE; /* don't repeat */ } void screen_show_desktop_popup(guint d, gboolean perm) { const Rect *a; + guint i; /* 0 means don't show the popup */ if (!config_desktop_popup_time) return; - 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, - (screen_desktop_layout.columns / - screen_desktop_layout.rows) / 2, - (screen_desktop_layout.rows/ - screen_desktop_layout.columns) / 2); - pager_popup_max_width(desktop_popup, - MAX(a->width/3, POPUP_WIDTH)); - pager_popup_show(desktop_popup, screen_desktop_names[d], d); - + for (i = 0; i < screen_num_monitors; i++) { + a = screen_physical_area_monitor(i); + pager_popup_position(desktop_popup[i], CenterGravity, + a->x + a->width / 2, a->y + a->height / 2); + pager_popup_icon_size_multiplier(desktop_popup[i], + (screen_desktop_layout.columns / + screen_desktop_layout.rows) / 2, + (screen_desktop_layout.rows/ + screen_desktop_layout.columns) / 2); + pager_popup_max_width(desktop_popup[i], + MAX(a->width/3, POPUP_WIDTH)); + pager_popup_show(desktop_popup[i], screen_desktop_names[d], d); + } if (desktop_popup_timer) g_source_remove(desktop_popup_timer); desktop_popup_timer = 0; if (!perm && !desktop_popup_perm) @@ -946,8 +980,12 @@ void screen_hide_desktop_popup(void) { if (desktop_popup_timer) g_source_remove(desktop_popup_timer); desktop_popup_timer = 0; - pager_popup_hide(desktop_popup); desktop_popup_perm = FALSE; + guint i; + + for (i = 0; i < screen_num_monitors; i++) { + pager_popup_hide(desktop_popup[i]); + } } guint screen_find_desktop(guint from, ObDirection dir, @@ -1182,9 +1220,11 @@ void screen_update_desktop_names(void) } /* resize the pager for these names */ - pager_popup_text_width_to_strings(desktop_popup, - screen_desktop_names, - screen_num_desktops); + for (i = 0; i < screen_num_monitors; i++) { + pager_popup_text_width_to_strings(desktop_popup[i], + screen_desktop_names, + screen_num_desktops); + } } void screen_show_desktop(ObScreenShowDestopMode show_mode, ObClient *show_only) @@ -1386,7 +1426,7 @@ static void get_xinerama_screens(Rect **xin_areas, guint *nxin) void screen_update_areas(void) { - guint i; + guint i, old_num_monitors = screen_num_monitors; gulong *dims; GList *it, *onscreen; @@ -1399,6 +1439,11 @@ void screen_update_areas(void) g_free(monitor_area); get_xinerama_screens(&monitor_area, &screen_num_monitors); + if (screen_num_monitors != old_num_monitors) { + if (desktop_popup) + desktop_popup_free(old_num_monitors); + desktop_popup_new(); + } /* set up the user-specified margins */ config_margins.top_start = RECT_LEFT(monitor_area[screen_num_monitors]); -- 2.39.2