static void workspace_renamed(WnckWorkspace* space, PagerData* pager) { int i; GtkTreeIter iter; i = wnck_workspace_get_number(space); if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(pager->workspaces_store), &iter, NULL, i)) gtk_list_store_set(pager->workspaces_store, &iter, 0, wnck_workspace_get_name(space), -1); }
static void workspace_created_cb (WnckScreen * screen, WnckWorkspace* workspace, gpointer user_data) { GtkWidget* button = workspace_button_new (workspace); gtk_widget_show (button); gtk_box_pack_start (user_data, button, TRUE, TRUE, 0); gtk_box_reorder_child (user_data, button, wnck_workspace_get_number (workspace)); }
static void workspace_destroyed_cb (WnckScreen * screen, WnckWorkspace* workspace, gpointer user_data) { GList * children; GtkWidget* button; children = gtk_container_get_children (user_data); button = g_list_nth_data (children, wnck_workspace_get_number (workspace)); gtk_container_remove (user_data, button); g_list_free (children); }
static void refill_submenu_workspace (WnckActionMenu *menu) { GtkWidget *submenu; GList *children; GList *l; int num_workspaces, window_space, i; WnckWorkspace *workspace; submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu->priv->workspace_item)); /* Remove existing items */ children = gtk_container_get_children (GTK_CONTAINER (submenu)); for (l = children; l; l = l->next) gtk_container_remove (GTK_CONTAINER (submenu), l->data); g_list_free (children); workspace = wnck_window_get_workspace (menu->priv->window); num_workspaces = wnck_screen_get_workspace_count (wnck_window_get_screen (menu->priv->window)); if (workspace) window_space = wnck_workspace_get_number (workspace); else window_space = -1; for (i = 0; i < num_workspaces; i++) { char *name; GtkWidget *item; name = get_workspace_name_with_accel (menu->priv->window, i); item = make_menu_item (MOVE_TO_WORKSPACE); g_object_set_data (G_OBJECT (item), "workspace", GINT_TO_POINTER (i)); if (i == window_space) gtk_widget_set_sensitive (item, FALSE); gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item); set_item_text (item, name); set_item_stock (item, NULL); g_free (name); } gtk_menu_reposition (GTK_MENU (submenu)); }
static void wnck_selector_workspace_created (WnckScreen *screen, WnckWorkspace *workspace, WnckSelector *selector) { if (!selector->priv->menu || !gtk_widget_get_visible (selector->priv->menu)) return; /* this is assuming that the new workspace will have a higher number * than all the old workspaces, which is okay since the old workspaces * didn't disappear in the meantime */ wnck_selector_add_workspace (selector, screen, wnck_workspace_get_number (workspace)); wnck_selector_make_menu_consistent (selector); gtk_menu_reposition (GTK_MENU (selector->priv->menu)); }
static void wnck_selector_workspace_destroyed (WnckScreen *screen, WnckWorkspace *workspace, WnckSelector *selector) { GList *l, *children; GtkWidget *destroy; int i; if (!selector->priv->menu || !gtk_widget_get_visible (selector->priv->menu)) return; destroy = NULL; i = wnck_workspace_get_number (workspace); /* search for the item of this workspace so that we destroy it */ children = gtk_container_get_children (GTK_CONTAINER (selector->priv->menu)); for (l = children; l; l = l->next) { int j; j = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (l->data), "wnck-selector-workspace-n")); if (j - 1 == i) destroy = GTK_WIDGET (l->data); else if (j - 1 > i) /* shift the following workspaces */ g_object_set_data (G_OBJECT (l->data), "wnck-selector-workspace-n", GINT_TO_POINTER (j - 1)); } g_list_free (children); if (destroy) gtk_widget_destroy (destroy); wnck_selector_make_menu_consistent (selector); gtk_menu_reposition (GTK_MENU (selector->priv->menu)); }
static void wnck_selector_insert_window (WnckSelector *selector, WnckWindow *window) { GtkWidget *item; WnckScreen *screen; WnckWorkspace *workspace; int workspace_n; int i; screen = wnck_selector_get_screen (selector); workspace = wnck_window_get_workspace (window); if (!workspace && !wnck_window_is_pinned (window)) return; item = wnck_selector_create_window (selector, window); if (!workspace || workspace == wnck_screen_get_active_workspace (screen)) { /* window is pinned or in the current workspace * => insert before the separator */ GList *l, *children; i = 0; children = gtk_container_get_children (GTK_CONTAINER (selector->priv->menu)); for (l = children; l; l = l->next) { if (GTK_IS_SEPARATOR_MENU_ITEM (l->data)) break; i++; } g_list_free (children); gtk_menu_shell_insert (GTK_MENU_SHELL (selector->priv->menu), item, i); } else { workspace_n = wnck_workspace_get_number (workspace); if (workspace_n == wnck_screen_get_workspace_count (screen) - 1) /* window is in last workspace => just append */ gtk_menu_shell_append (GTK_MENU_SHELL (selector->priv->menu), item); else { /* insert just before the next workspace item */ GList *l, *children; i = 0; children = gtk_container_get_children (GTK_CONTAINER (selector->priv->menu)); for (l = children; l; l = l->next) { int j; j = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (l->data), "wnck-selector-workspace-n")); if (j - 1 == workspace_n + 1) break; i++; } g_list_free (children); gtk_menu_shell_insert (GTK_MENU_SHELL (selector->priv->menu), item, i); } } }
static void wnck_selector_make_menu_consistent (WnckSelector *selector) { GList *l, *children; int workspace_n; GtkWidget *workspace_item; GtkWidget *separator; gboolean separator_is_first; gboolean separator_is_last; gboolean visible_window; workspace_n = -1; workspace_item = NULL; separator = NULL; separator_is_first = FALSE; separator_is_last = FALSE; visible_window = FALSE; children = gtk_container_get_children (GTK_CONTAINER (selector->priv->menu)); for (l = children; l; l = l->next) { int i; i = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (l->data), "wnck-selector-workspace-n")); if (i > 0) { workspace_n = i - 1; /* we have two consecutive workspace items => hide the first */ if (workspace_item) gtk_widget_hide (workspace_item); workspace_item = GTK_WIDGET (l->data); } else if (GTK_IS_SEPARATOR_MENU_ITEM (l->data)) { if (!visible_window) separator_is_first = TRUE; separator_is_last = TRUE; separator = GTK_WIDGET (l->data); } else if (gtk_widget_get_visible (l->data) && l->data != selector->priv->no_windows_item) { separator_is_last = FALSE; visible_window = TRUE; /* if we know of a workspace item that was not shown */ if (workspace_item) { WnckWindow *window; WnckWorkspace *workspace; window = g_object_get_data (G_OBJECT (l->data), "wnck-selector-window"); if (window) { workspace = wnck_window_get_workspace (window); if (workspace && workspace_n == wnck_workspace_get_number (workspace)) { gtk_widget_show (workspace_item); workspace_n = -1; workspace_item = NULL; } } } } /* end if (normal item) */ } g_list_free (children); /* do we have a trailing workspace item to be hidden? */ if (workspace_item) gtk_widget_hide (workspace_item); if (separator) { if (separator_is_first || separator_is_last) gtk_widget_hide (separator); else gtk_widget_show (separator); } if (visible_window) gtk_widget_hide (selector->priv->no_windows_item); else gtk_widget_show (selector->priv->no_windows_item); }
static void wnck_selector_on_show (GtkWidget *widget, WnckSelector *selector) { GtkWidget *separator; WnckScreen *screen; WnckWorkspace *workspace; int nb_workspace; int i; GList **windows_per_workspace; GList *windows; GList *l, *children; /* Remove existing items */ children = gtk_container_get_children (GTK_CONTAINER (selector->priv->menu)); for (l = children; l; l = l->next) gtk_container_remove (GTK_CONTAINER (selector->priv->menu), l->data); g_list_free (children); if (selector->priv->window_hash) g_hash_table_destroy (selector->priv->window_hash); selector->priv->window_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); screen = wnck_selector_get_screen (selector); nb_workspace = wnck_screen_get_workspace_count (screen); windows_per_workspace = g_malloc0 (nb_workspace * sizeof (GList *)); /* Get windows ordered by workspaces */ windows = wnck_screen_get_windows (screen); windows = g_list_sort (windows, wnck_selector_windows_compare); for (l = windows; l; l = l->next) { workspace = wnck_window_get_workspace (l->data); if (!workspace && wnck_window_is_pinned (l->data)) workspace = wnck_screen_get_active_workspace (screen); if (!workspace) continue; i = wnck_workspace_get_number (workspace); windows_per_workspace[i] = g_list_prepend (windows_per_workspace[i], l->data); } /* Add windows from the current workspace */ workspace = wnck_screen_get_active_workspace (screen); if (workspace) { i = wnck_workspace_get_number (workspace); windows_per_workspace[i] = g_list_reverse (windows_per_workspace[i]); for (l = windows_per_workspace[i]; l; l = l->next) wnck_selector_append_window (selector, l->data); g_list_free (windows_per_workspace[i]); windows_per_workspace[i] = NULL; } /* Add separator */ separator = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (selector->priv->menu), separator); /* Add windows from other workspaces */ for (i = 0; i < nb_workspace; i++) { wnck_selector_add_workspace (selector, screen, i); windows_per_workspace[i] = g_list_reverse (windows_per_workspace[i]); for (l = windows_per_workspace[i]; l; l = l->next) wnck_selector_append_window (selector, l->data); g_list_free (windows_per_workspace[i]); windows_per_workspace[i] = NULL; } g_free (windows_per_workspace); selector->priv->no_windows_item = wnck_selector_item_new (selector, _("No Windows Open"), NULL); gtk_widget_set_sensitive (selector->priv->no_windows_item, FALSE); gtk_menu_shell_append (GTK_MENU_SHELL (selector->priv->menu), selector->priv->no_windows_item); wnck_selector_make_menu_consistent (selector); }
static gboolean applet_scroll (PanelApplet *applet, GdkEventScroll *event, PagerData *pager) { WnckScreen *screen; int index; int n_workspaces; int n_columns; int in_last_row; if (event->type != GDK_SCROLL) return FALSE; screen = wncklet_get_screen (GTK_WIDGET (applet)); index = wnck_workspace_get_number (wnck_screen_get_active_workspace (screen)); n_workspaces = wnck_screen_get_workspace_count (screen); n_columns = n_workspaces / pager->n_rows; if (n_workspaces % pager->n_rows != 0) n_columns++; in_last_row = n_workspaces % n_columns; switch (event->direction) { case GDK_SCROLL_DOWN: if (index + n_columns < n_workspaces) index += n_columns; else if ((index < n_workspaces - 1 && index + in_last_row != n_workspaces - 1) || (index == n_workspaces - 1 && in_last_row != 0)) index = (index % n_columns) + 1; break; case GDK_SCROLL_RIGHT: if (index < n_workspaces - 1) index++; break; case GDK_SCROLL_UP: if (index - n_columns >= 0) index -= n_columns; else if (index > 0) index = ((pager->n_rows - 1) * n_columns) + (index % n_columns) - 1; if (index >= n_workspaces) index -= n_columns; break; case GDK_SCROLL_LEFT: if (index > 0) index--; break; default: g_assert_not_reached (); break; } wnck_workspace_activate (wnck_screen_get_workspace (screen, index), event->time); return TRUE; }
static gboolean applet_scroll(MatePanelApplet* applet, GdkEventScroll* event, PagerData* pager) { GdkScrollDirection absolute_direction; int index; int n_workspaces; int n_columns; int in_last_row; if (event->type != GDK_SCROLL) return FALSE; index = wnck_workspace_get_number(wnck_screen_get_active_workspace(pager->screen)); n_workspaces = wnck_screen_get_workspace_count(pager->screen); n_columns = n_workspaces / pager->n_rows; if (n_workspaces % pager->n_rows != 0) n_columns++; in_last_row = n_workspaces % n_columns; absolute_direction = event->direction; if (gtk_widget_get_direction(GTK_WIDGET(applet)) == GTK_TEXT_DIR_RTL) { switch (event->direction) { case GDK_SCROLL_DOWN: case GDK_SCROLL_UP: break; case GDK_SCROLL_RIGHT: absolute_direction = GDK_SCROLL_LEFT; break; case GDK_SCROLL_LEFT: absolute_direction = GDK_SCROLL_RIGHT; break; } } switch (absolute_direction) { case GDK_SCROLL_DOWN: if (index + n_columns < n_workspaces) { index += n_columns; } else if (pager->wrap_workspaces && index == n_workspaces - 1) { index = 0; } else if ((index < n_workspaces - 1 && index + in_last_row != n_workspaces - 1) || (index == n_workspaces - 1 && in_last_row != 0)) { index = (index % n_columns) + 1; } break; case GDK_SCROLL_RIGHT: if (index < n_workspaces - 1) { index++; } else if (pager->wrap_workspaces) { index = 0; } break; case GDK_SCROLL_UP: if (index - n_columns >= 0) { index -= n_columns; } else if (index > 0) { index = ((pager->n_rows - 1) * n_columns) + (index % n_columns) - 1; } else if (pager->wrap_workspaces) { index = n_workspaces - 1; } if (index >= n_workspaces) index -= n_columns; break; case GDK_SCROLL_LEFT: if (index > 0) { index--; } else if (pager->wrap_workspaces) { index = n_workspaces - 1; } break; default: g_assert_not_reached(); break; } wnck_workspace_activate(wnck_screen_get_workspace(pager->screen, index), event->time); return TRUE; }