From 8a8171ebc7543c793e1c8c858c72daaafa94fa44 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sat, 22 Jun 2002 05:11:04 +0000 Subject: [PATCH] do nothing if screen is being unmanaged, we don't want to blow away state, 2002-06-22 Havoc Pennington * src/workspace.c (set_number_of_spaces_hint): do nothing if screen is being unmanaged, we don't want to blow away state, we want to remember it for the next window manager. 2002-06-22 Havoc Pennington * src/workspace.c (meta_screen_ensure_workspace_popup): rename from meta_workspace_ensure_tab_popup, and use workspace->name instead of a hardcoded name --- ChangeLog | 12 +++++ src/display.c | 6 ++- src/display.h | 3 ++ src/screen.c | 125 +++++++++++++++++++++++++++++++++++++++++++ src/screen.h | 9 ++++ src/workspace.c | 138 +++--------------------------------------------- src/workspace.h | 3 -- 7 files changed, 161 insertions(+), 135 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2a860436f..5cc63c481 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2002-06-22 Havoc Pennington + + * src/workspace.c (set_number_of_spaces_hint): do nothing if + screen is being unmanaged, we don't want to blow away state, + we want to remember it for the next window manager. + +2002-06-22 Havoc Pennington + + * src/workspace.c (meta_screen_ensure_workspace_popup): rename + from meta_workspace_ensure_tab_popup, and use workspace->name + instead of a hardcoded name + 2002-06-22 Havoc Pennington * src/xprops.c (meta_prop_get_utf8_list): new utility function diff --git a/src/display.c b/src/display.c index 32c09f4ad..d08d2f20c 100644 --- a/src/display.c +++ b/src/display.c @@ -262,6 +262,8 @@ meta_display_open (const char *name) display = g_new (MetaDisplay, 1); + display->closing = 0; + /* here we use XDisplayName which is what the user * probably put in, vs. DisplayString(display) which is * canonicalized by XOpenDisplay() @@ -556,6 +558,8 @@ meta_display_close (MetaDisplay *display) if (display->error_traps > 0) meta_bug ("Display closed with error traps pending\n"); + display->closing += 1; + if (display->autoraise_timeout_id != 0) { g_source_remove (display->autoraise_timeout_id); @@ -2267,7 +2271,7 @@ meta_display_begin_grab_op (MetaDisplay *display, break; case META_GRAB_OP_KEYBOARD_WORKSPACE_SWITCHING: - meta_workspace_ensure_tab_popup (display, window->screen); + meta_screen_ensure_workspace_popup (window->screen); break; default: diff --git a/src/display.h b/src/display.h index 1b26ad9e5..4620030f8 100644 --- a/src/display.h +++ b/src/display.h @@ -220,6 +220,9 @@ struct _MetaDisplay /* Xinerama cache */ unsigned int xinerama_cache_invalidated : 1; + + /* Closing down the display */ + int closing; }; gboolean meta_display_open (const char *name); diff --git a/src/screen.c b/src/screen.c index aef9e82b8..b5d6473c6 100644 --- a/src/screen.c +++ b/src/screen.c @@ -314,6 +314,7 @@ meta_screen_new (MetaDisplay *display, } screen = g_new (MetaScreen, 1); + screen->closing = 0; screen->display = display; screen->number = number; @@ -493,6 +494,8 @@ meta_screen_free (MetaScreen *screen) MetaDisplay *display; display = screen->display; + + screen->closing += 1; meta_display_grab (display); @@ -922,6 +925,79 @@ meta_screen_ensure_tab_popup (MetaScreen *screen, /* don't show tab popup, since proper window isn't selected yet */ } +void +meta_screen_ensure_workspace_popup (MetaScreen *screen) +{ + MetaTabEntry *entries; + GdkPixbuf *icon; + int len, rows, cols; + int i; + + if (screen->tab_popup) + return; + + icon = meta_ui_get_default_window_icon (NULL); + + len = meta_screen_get_n_workspaces (screen); + + entries = g_new (MetaTabEntry, len + 1); + entries[len].key = NULL; + entries[len].title = NULL; + entries[len].icon = NULL; + + meta_screen_calc_workspace_layout (screen, len, &rows, &cols); + + if (screen->vertical_workspaces) + { + int j, k; + + for (i = 0; i < rows; ++i) + { + for (j = 0; j < cols; ++j) + { + MetaWorkspace *workspace; + + k = i + (j * rows); + workspace = meta_display_get_workspace_by_index (screen->display, + k); + + g_assert (workspace); + + entries[i].key = (MetaTabEntryKey) workspace; + entries[i].title = workspace->name; + entries[i].icon = icon; + } + } + } + else + { + for (i = 0; i < len; ++i) + { + MetaWorkspace *workspace; + + workspace = meta_display_get_workspace_by_index (screen->display, i); + + g_assert (workspace); + + entries[i].key = (MetaTabEntryKey) workspace; + entries[i].title = workspace->name; + entries[i].icon = icon; + } + } + + screen->tab_popup = meta_ui_tab_popup_new (entries, + screen->number, + len, + cols, + FALSE); + + g_free (entries); + + g_object_unref (G_OBJECT (icon)); + + /* don't show tab popup, since proper window isn't selected yet */ +} + /* Focus top window on active workspace */ void meta_screen_focus_top_window (MetaScreen *screen, @@ -1175,3 +1251,52 @@ meta_create_offscreen_window (Display *xdisplay, CWOverrideRedirect, &attrs); } + +void +meta_screen_calc_workspace_layout (MetaScreen *screen, + int num_workspaces, + int *r, + int *c) +{ + int cols, rows; + + /* + * 3 rows, 4 columns, horizontal layout: + * +--+--+--+--+ + * | 1| 2| 3| 4| + * +--+--+--+--+ + * | 5| 6| 7| 8| + * +--+--+--+--+ + * | 9|10|11|12| + * +--+--+--+--+ + * + * vertical layout: + * +--+--+--+--+ + * | 1| 4| 7|10| + * +--+--+--+--+ + * | 2| 5| 8|11| + * +--+--+--+--+ + * | 3| 6| 9|12| + * +--+--+--+--+ + * + */ + + rows = screen->rows_of_workspaces; + cols = screen->columns_of_workspaces; + if (rows <= 0 && cols <= 0) + cols = num_workspaces; + + if (rows <= 0) + rows = num_workspaces / cols + ((num_workspaces % cols) > 0 ? 1 : 0); + if (cols <= 0) + cols = num_workspaces / rows + ((num_workspaces % rows) > 0 ? 1 : 0); + + /* paranoia */ + if (rows < 1) + rows = 1; + if (cols < 1) + cols = 1; + + *r = rows; + *c = cols; +} diff --git a/src/screen.h b/src/screen.h index 018348e5e..cd374f2f2 100644 --- a/src/screen.h +++ b/src/screen.h @@ -77,6 +77,8 @@ struct _MetaScreen guint vertical_workspaces : 1; guint keys_grabbed : 1; + + int closing; }; MetaScreen* meta_screen_new (MetaDisplay *display, @@ -98,6 +100,8 @@ void meta_screen_set_cursor (MetaScreen *scree void meta_screen_ensure_tab_popup (MetaScreen *screen, MetaTabList type); +void meta_screen_ensure_workspace_popup (MetaScreen *screen); + void meta_screen_focus_top_window (MetaScreen *screen, MetaWindow *not_this_one); @@ -111,6 +115,11 @@ void meta_screen_update_workspace_names (MetaScreen *scree Window meta_create_offscreen_window (Display *xdisplay, Window parent); +void meta_screen_calc_workspace_layout (MetaScreen *screen, + int num_workspaces, + int *r, + int *c); + #endif diff --git a/src/workspace.c b/src/workspace.c index 984326759..fdde992cb 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -310,6 +310,9 @@ static int set_number_of_spaces_hint (MetaScreen *screen) { unsigned long data[1]; + + if (screen->closing > 0) + return 0; data[0] = meta_screen_get_n_workspaces (screen); @@ -521,52 +524,6 @@ meta_workspace_get_work_area (MetaWorkspace *workspace, *area = workspace->work_area; } -static void -calc_rows_and_cols (MetaScreen *screen, int num_workspaces, int *r, int *c) -{ - int cols, rows; - - /* - * 3 rows, 4 columns, horizontal layout: - * +--+--+--+--+ - * | 1| 2| 3| 4| - * +--+--+--+--+ - * | 5| 6| 7| 8| - * +--+--+--+--+ - * | 9|10|11|12| - * +--+--+--+--+ - * - * vertical layout: - * +--+--+--+--+ - * | 1| 4| 7|10| - * +--+--+--+--+ - * | 2| 5| 8|11| - * +--+--+--+--+ - * | 3| 6| 9|12| - * +--+--+--+--+ - * - */ - - rows = screen->rows_of_workspaces; - cols = screen->columns_of_workspaces; - if (rows <= 0 && cols <= 0) - cols = num_workspaces; - - if (rows <= 0) - rows = num_workspaces / cols + ((num_workspaces % cols) > 0 ? 1 : 0); - if (cols <= 0) - cols = num_workspaces / rows + ((num_workspaces % rows) > 0 ? 1 : 0); - - /* paranoia */ - if (rows < 1) - rows = 1; - if (cols < 1) - cols = 1; - - *r = rows; - *c = cols; -} - MetaWorkspace* meta_workspace_get_neighbor (MetaWorkspace *workspace, MetaMotionDirection direction) @@ -577,7 +534,8 @@ meta_workspace_get_neighbor (MetaWorkspace *workspace, i = meta_workspace_index (workspace); num_workspaces = meta_screen_get_n_workspaces (workspace->screen); - calc_rows_and_cols (workspace->screen, num_workspaces, &rows, &cols); + meta_screen_calc_workspace_layout (workspace->screen, num_workspaces, + &rows, &cols); grid_area = rows * cols; @@ -665,8 +623,8 @@ meta_workspace_get_neighbor (MetaWorkspace *workspace, else i += cols; break; - } - } + } + } meta_verbose ("Neighbor space is %d\n", i); @@ -674,88 +632,6 @@ meta_workspace_get_neighbor (MetaWorkspace *workspace, i); } -void -meta_workspace_ensure_tab_popup (MetaDisplay *display, - MetaScreen *screen) -{ - MetaTabEntry *entries; - GdkPixbuf *icon; - int len, rows, cols; - int i; - - if (screen->tab_popup) - return; - - icon = meta_ui_get_default_window_icon (NULL); - - len = meta_screen_get_n_workspaces (screen); - - entries = g_new (MetaTabEntry, len + 1); - entries[len].key = NULL; - entries[len].title = NULL; - entries[len].icon = NULL; - - calc_rows_and_cols (screen, len, &rows, &cols); - - if (screen->vertical_workspaces) - { - int j, k; - - for (i = 0; i < rows; ++i) - { - for (j = 0; j < cols; ++j) - { - MetaWorkspace *workspace; - char *title; - - k = i + (j * rows); - workspace = meta_display_get_workspace_by_index (display, k); - - g_assert (workspace); - - title = g_strdup_printf (_("Workspace %d"), k + 1); - - entries[i].key = (MetaTabEntryKey) workspace; - entries[i].title = title; - entries[i].icon = icon; - } - } - } - else - { - for (i = 0; i < len; ++i) - { - MetaWorkspace *workspace; - char *title; - - workspace = meta_display_get_workspace_by_index (display, i); - - g_assert (workspace); - - title = g_strdup_printf (_("Workspace %d"), i + 1); - - entries[i].key = (MetaTabEntryKey) workspace; - entries[i].title = title; - entries[i].icon = icon; - } - } - - screen->tab_popup = meta_ui_tab_popup_new (entries, - screen->number, - len, - cols, - FALSE); - - for (i = 0; i < len; ++i) - g_free((void *) entries[i].title); - - g_free (entries); - - g_object_unref (G_OBJECT (icon)); - - /* don't show tab popup, since proper window isn't selected yet */ -} - void meta_workspace_set_name (MetaWorkspace *workspace, const char *name) diff --git a/src/workspace.h b/src/workspace.h index 8fbdc74c0..248c159df 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -71,9 +71,6 @@ void meta_workspace_get_work_area (MetaWorkspace *workspace, MetaWorkspace* meta_workspace_get_neighbor (MetaWorkspace *workspace, MetaMotionDirection direction); -void meta_workspace_ensure_tab_popup (MetaDisplay *display, - MetaScreen *screen); - void meta_workspace_set_name (MetaWorkspace *workspace, const char *name);