void Application::init() { b2Vec2 gravity(0.0f, 10.0f); mWorld = QSharedPointer<b2World>(new b2World(gravity)); mWorld->SetAllowSleeping(false); // Get windowing system WnckScreen *screen; WnckWindow *active_window; WnckWorkspace *active_workspace; GList *window_l; screen = wnck_screen_get_default (); wnck_screen_force_update (screen); active_window = wnck_screen_get_active_window (screen); active_workspace = wnck_screen_get_active_workspace (screen); for(window_l = wnck_screen_get_windows (screen); window_l != NULL; window_l = window_l->next) { WnckWindow *window = WNCK_WINDOW (window_l->data); if(wnck_window_is_on_workspace(window, active_workspace) && !wnck_window_is_minimized(window) && wnck_window_get_window_type(window) == WNCK_WINDOW_NORMAL) { mPhysicalWindows.append(QSharedPointer<PhysicalWindow>(new PhysicalWindow(window, mWorld))); } } mPhysicalWindows.append(QSharedPointer<PhysicalWindow>(new PhysicalWindow(100, 100, 100, 100, mWorld))); }
/* Returns the number of window for this application that reside on the current workspace */ int LauncherApplication::windowCountOnCurrentWorkspace() { int windowCount = 0; WnckWorkspace *current = wnck_screen_get_active_workspace(wnck_screen_get_default()); for (int i = 0; i < m_application->windows()->size(); i++) { BamfWindow *window = m_application->windows()->at(i); if (window == NULL) { continue; } /* When geting the wnck window, it's possible we get a NULL return value because wnck hasn't updated its internal list yet, so we need to force it once to be sure */ WnckWindow *wnck_window = wnck_window_get(window->xid()); if (wnck_window == NULL) { wnck_screen_force_update(wnck_screen_get_default()); wnck_window = wnck_window_get(window->xid()); if (wnck_window == NULL) { continue; } } WnckWorkspace *workspace = wnck_window_get_workspace(wnck_window); if (workspace == current) { windowCount++; } } return windowCount; }
void init_wnck (WckUtils *win, gboolean only_maximized, gpointer data) { /* save data */ win->data = data; /* get window proprieties */ win->activescreen = wnck_screen_get_default(); win->activeworkspace = wnck_screen_get_active_workspace(win->activescreen); if (!win->activeworkspace) win->activeworkspace = wnck_screen_get_workspace(win->activescreen, 0); win->activewindow = wnck_screen_get_active_window(win->activescreen); win->umaxwindow = NULL; win->controlwindow = NULL; win->only_maximized = only_maximized; /* Global window tracking */ g_signal_connect(win->activescreen, "active-window-changed", G_CALLBACK (active_window_changed), win); if (win->only_maximized) { win->sch = g_signal_connect(win->activescreen, "window-closed", G_CALLBACK (on_window_closed), win); win->soh = g_signal_connect(win->activescreen, "window-opened", G_CALLBACK (on_window_opened), win); } win->svh = g_signal_connect(win->activescreen, "viewports-changed", G_CALLBACK (on_viewports_changed), win); win->swh = g_signal_connect(win->activescreen, "active-workspace-changed", G_CALLBACK (active_workspace_changed), win); /* Get controled window */ track_controled_window (win); if (!win->controlwindow) on_control_window_changed (NULL, NULL, win->data); }
int c_center(lua_State *lua) { int top = lua_gettop(lua); int workspace_width, workspace_height, window_width, window_height; int xoffset, yoffset; WnckScreen *screen; WnckWorkspace *workspace; if (top != 0) { luaL_error(lua, "center: %s", no_indata_expected_error); return 0; } WnckWindow *window = get_current_window(); if (!window) { lua_pushboolean(lua, FALSE); return 1; } wnck_window_get_geometry(window, NULL, NULL, &window_width, &window_height); screen = wnck_window_get_screen(window); workspace = wnck_screen_get_active_workspace(screen); if (workspace == NULL) { workspace = wnck_screen_get_workspace(screen,0); } if (workspace == NULL) { g_printerr(_("Could not get workspace")); lua_pushboolean(lua, FALSE); return 1; } workspace_width = wnck_workspace_get_width(workspace); workspace_height = wnck_workspace_get_height(workspace); xoffset = (workspace_width - window_width) / 2; yoffset = (workspace_height - window_height) / 2; devilspie2_error_trap_push(); XMoveWindow (gdk_x11_get_default_xdisplay(), wnck_window_get_xid(window), xoffset, yoffset); if (devilspie2_error_trap_pop()) { g_printerr("center: %s", failed_string); lua_pushboolean(lua, FALSE); return 1; } lua_pushboolean(lua, TRUE); return 1; }
// ----------------------------------------------------------------------------- void g_window_workspace(GtkWidget* pWidget, int space) { DEBUGLOGB; #if !_USEWKSPACE #if GTK_CHECK_VERSION(3,0,0) Screen* xscreen = gdk_x11_screen_get_xscreen(gdk_screen_get_default()); Window xwindow = gdk_x11_window_get_xid(gtk_widget_get_window(pWidget)); #else Screen* xscreen = GDK_SCREEN_XSCREEN(gdk_screen_get_default()); Window xwindow = GDK_WINDOW_XWINDOW(gtk_widget_get_window(pWidget)); #endif _wncki_change_workspace(xscreen, xwindow, space); #else // !_USEWKSPACE WnckScreen* screen = wnck_screen_get_default(); if( screen ) { DEBUGLOGS("got default screen"); wnck_screen_force_update(screen); DEBUGLOGP("sticky is off and workspace is %d\n", space); WnckWindow* window = wnck_window_get(gdk_x11_drawable_get_xid(gtk_widget_get_window(pWidget))); if( window && !wnck_window_is_pinned(window) ) { DEBUGLOGS("got non-pinned window"); WnckWorkspace* trgtWrk = wnck_screen_get_workspace (screen, space); WnckWorkspace* actvWrk = wnck_screen_get_active_workspace(screen); if( trgtWrk && actvWrk && trgtWrk != actvWrk ) { DEBUGLOGS("got target workspace is diff from current so moving window to target"); wnck_window_move_to_workspace(window, trgtWrk); } } #ifdef _DEBUGLOG else { DEBUGLOGP("WnckWindow for clock window is%svalid\n", window ? " " : " NOT "); guint xw1 = GDK_WINDOW_XWINDOW (gtk_widget_get_window(pWidget)); guint xw2 = gdk_x11_drawable_get_xid(gtk_widget_get_window(pWidget)); DEBUGLOGP("X11 XID1 for clock window is %d\n", (int)xw1); DEBUGLOGP("X11 XID2 for clock window is %d\n", (int)xw2); } #endif } #endif // !_USEWKSPACE DEBUGLOGE; }
/* Triggers when user changes viewports (Compiz) */ static void viewports_changed (WnckScreen *screen, WTApplet *wtapplet) { wtapplet->activeworkspace = wnck_screen_get_active_workspace(screen); wtapplet->activewindow = wnck_screen_get_active_window(screen); wtapplet->rootwindow = getRootWindow(wtapplet->activescreen); //? wtapplet->umaxedwindow = getUpperMaximized(wtapplet); // active_window_changed will do it too, but this one will be sooner updateTitle(wtapplet); }
/* Triggers when.... ? not sure... (Metacity?) */ static void active_workspace_changed (WnckScreen *screen, WnckWorkspace *previous, WTApplet *wtapplet) { wtapplet->activeworkspace = wnck_screen_get_active_workspace(screen); /* wtapplet->activewindow = wnck_screen_get_active_window(screen); // wtapplet->rootwindow = getRootWindow(wtapplet->activescreen); //? wtapplet->umaxedwindow = getUpperMaximized(wtapplet); updateTitle(wtapplet); */ }
static void active_window_changed (WnckScreen* screen, WnckWindow* previous, gpointer user_data) { WorkspaceButton* self = user_data; WnckWindow * current = wnck_screen_get_active_window (screen); if (current && wnck_window_is_on_workspace (current, PRIV (self)->workspace) && wnck_screen_get_active_workspace (screen) == PRIV (self)->workspace) { set_active_window (self, current); } }
gboolean dnd_has_one_fullscreen_window (void) { gboolean result; WnckScreen *screen = wnck_screen_get_default (); wnck_screen_force_update (screen); WnckWorkspace *workspace = wnck_screen_get_active_workspace (screen); GList *list = wnck_screen_get_windows (screen); GList *item = g_list_find_custom (list, workspace, (GCompareFunc) is_fullscreen_cb); result = item != NULL; #ifdef HAVE_WNCK_SHUTDOWN wnck_shutdown (); #endif return result; }
static void task_item_set_visibility (TaskItem *item) { WnckScreen *screen; WnckWindow *window; WnckWorkspace *workspace; g_return_if_fail (TASK_IS_ITEM (item)); TaskItemPrivate *priv = item->priv; if (!WNCK_IS_WINDOW (priv->window)) { gtk_widget_hide (GTK_WIDGET (item)); return; } window = priv->window; screen = priv->screen; workspace = wnck_screen_get_active_workspace (screen); gboolean show_all = task_list_get_show_all_windows (TASK_LIST (task_list_get_default ())); gboolean show_window = FALSE; if (!wnck_window_is_skip_tasklist (window)) { if (wnck_workspace_is_virtual (workspace)) { show_window = wnck_window_is_in_viewport (window, workspace); } else { show_window = wnck_window_is_on_workspace (window, workspace); } show_window = show_window || show_all; } if (show_window) { gtk_widget_show (GTK_WIDGET (item)); } else { gtk_widget_hide (GTK_WIDGET (item)); } }
static gboolean is_window_on_active_workspace_and_no_other_maximized_windows_above(WnckWindow *window) { WnckWorkspace *workspace = wnck_window_get_workspace(window); WnckScreen *screen = wnck_workspace_get_screen(workspace); if (wnck_screen_get_active_workspace(screen) != workspace) { return FALSE; } GList *windows = wnck_screen_get_windows_stacked(screen); GList *top_window = g_list_last(windows); GList *bottom_window = g_list_first(windows); while (top_window->data != window && top_window != bottom_window) { if (wnck_window_is_maximized((WnckWindow *)top_window->data)) { return FALSE; } top_window = top_window->prev; } return TRUE; }
/** * ww_apply_layout_by_name * @layout_name: The name of the layout to apply * * Apply a given layout to the default screen by looking up the relevant * #WwLayout based on its name. */ void ww_apply_layout_by_name (const gchar * layout_name) { WnckScreen *screen; WnckWorkspace *current_ws; GList *windows, *struts; WnckWindow *active; const WwLayout *layout; GError *error; screen = wnck_screen_get_default (); wnck_screen_force_update (screen); current_ws = wnck_screen_get_active_workspace (screen); windows = wnck_screen_get_windows (screen); struts = ww_filter_strut_windows (windows, current_ws); windows = ww_filter_user_windows (windows, current_ws); active = wnck_screen_get_active_window (screen); /* Check that we know the requested layout */ layout = ww_get_layout (layout_name); if (!layout) { g_printerr ("No such layout: '%s'. Try running with --layouts to " "list possible layouts\n", layout_name); return; } /* Apply the layout */ error = NULL; layout->handler (screen, windows, struts, active, &error); g_list_free (windows); g_list_free (struts); if (error) { g_printerr ("Failed to apply layout '%s'. Error was:\n%s", layout_name, error->message); g_error_free (error); return; } }
static void window_item_activated (GtkWidget * widget, WnckWindow* window) { WnckWorkspace* workspace = wnck_window_get_workspace (window); if (workspace && wnck_screen_get_active_workspace (wnck_window_get_screen (window)) != workspace) { wnck_workspace_activate (workspace, gtk_get_current_event_time ()); } if (wnck_screen_get_active_window (wnck_window_get_screen (window)) == window) { wnck_window_minimize (window); } else { wnck_window_activate_transient (window, gtk_get_current_event_time ()); } }
static void on_active_window_changed(WnckScreen *screen, WnckWindow *previously_active_window, gpointer user_data) { GList *window_l; WnckWindow *active_window = wnck_screen_get_active_window(screen); WnckWorkspace *active_workspace = wnck_screen_get_active_workspace(screen); GList *pids_current = NULL; GList *pids_other = NULL; for (window_l = wnck_screen_get_windows(screen); window_l != NULL; window_l = window_l->next) { WnckWindow *window = WNCK_WINDOW(window_l->data); WnckApplication *app = wnck_application_get(wnck_window_get_group_leader(window)); WnckWorkspace *w_workspace = wnck_window_get_workspace(window); if (!w_workspace) continue; GList *app_window_l; int w_pid = wnck_application_get_pid(app); if (w_workspace == active_workspace) { GList *g = g_list_find(pids_current, GINT_TO_POINTER(w_pid)); if (!g) pids_current = g_list_append(pids_current, GINT_TO_POINTER(w_pid)); } else { GList *g = g_list_find(pids_other, GINT_TO_POINTER(w_pid)); if (!g) pids_other = g_list_append(pids_other, GINT_TO_POINTER(w_pid)); } } for (; pids_other != NULL; pids_other = pids_other->next) { GList *g = g_list_find(pids_current, pids_other->data); if (g) g_print("Another window of this application is active\n"); else g_print("PID: %d\n", stop_pid(GPOINTER_TO_INT(pids_other->data))); } for (; pids_current != NULL; pids_current = pids_current->next) { cont_pid(GPOINTER_TO_INT(pids_current->data)); } g_print("-----\n"); }
static gboolean on_task_item_button_released (GtkWidget *widget, GdkEventButton *event, TaskItem *item) { WnckWindow *window; WnckScreen *screen; WnckWorkspace *workspace; TaskItemPrivate *priv; g_return_val_if_fail (TASK_IS_ITEM (item), TRUE); priv = item->priv; window = priv->window; g_return_val_if_fail (WNCK_IS_WINDOW (window), TRUE); screen = priv->screen; workspace = wnck_window_get_workspace (window); if (event->button == 1) { if (WNCK_IS_WORKSPACE (workspace) && workspace != wnck_screen_get_active_workspace (screen)) { wnck_workspace_activate (workspace, GDK_CURRENT_TIME); } if (wnck_window_is_active (window)) { wnck_window_minimize (window); } else { wnck_window_activate (window, GDK_CURRENT_TIME); } } return TRUE; }
static void wibuti_watcher_find_window(WibutiWatcher *self) { WnckWorkspace *activeworkspace = wnck_screen_get_active_workspace(self->screen); WnckWindow *new_active = wnck_screen_get_active_window(self->screen); WnckWindow *new_tracked = NULL; // stop tracking the old active window if (G_IS_OBJECT(self->active)) { if (g_signal_handler_is_connected(G_OBJECT(self->active), self->handler_active_state_changed)) { g_signal_handler_disconnect(G_OBJECT(self->active), self->handler_active_state_changed); } } if (self->only_maximized) { // find upper maximized window GList *windows = wnck_screen_get_windows_stacked(self->screen); while (windows && windows->data) { if (!self->only_maximized || wnck_window_is_maximized(windows->data)) if (!wnck_window_is_minimized(windows->data) && !wnck_window_is_skip_pager(windows->data)) if (wnck_window_is_in_viewport(windows->data, activeworkspace)) new_tracked = windows->data; windows = windows->next; } // start tracking the new active window if (new_active) { self->handler_active_state_changed = g_signal_connect(G_OBJECT(new_active), "state-changed", G_CALLBACK(wibuti_watcher_window_state_changed_cb), self); } } else { new_tracked = new_active; } // stop tracking the old window if (G_IS_OBJECT(self->tracked)) { #ifdef WIBUTI_WITH_TITLE if (g_signal_handler_is_connected(G_OBJECT(self->tracked), self->handler_name_changed)) { g_signal_handler_disconnect(G_OBJECT(self->tracked), self->handler_name_changed); } if (g_signal_handler_is_connected(G_OBJECT(self->tracked), self->handler_icon_changed)) { g_signal_handler_disconnect(G_OBJECT(self->tracked), self->handler_icon_changed); } #endif // WIBUTI_WITH_TITLE if (g_signal_handler_is_connected(G_OBJECT(self->tracked), self->handler_tracked_state_changed)) { g_signal_handler_disconnect(G_OBJECT(self->tracked), self->handler_tracked_state_changed); } } // start tracking the new window if (new_tracked) { #ifdef WIBUTI_WITH_TITLE self->handler_name_changed = g_signal_connect(G_OBJECT(new_tracked), "name-changed", G_CALLBACK(wibuti_watcher_name_changed_cb), self); self->handler_icon_changed = g_signal_connect(G_OBJECT(new_tracked), "icon-changed", G_CALLBACK(wibuti_watcher_icon_changed_cb), self); #endif // WIBUTI_WITH_TITLE self->handler_tracked_state_changed = g_signal_connect(G_OBJECT(new_tracked), "state-changed", G_CALLBACK(wibuti_watcher_window_state_changed_cb), self); } self->tracked = new_tracked; self->active = new_active; }
static void workspace_changed_cb(WnckScreen *screen_cb, gpointer data) { WnckWorkspace *workspace; const char *workspace_name; char *color_shading_type; char *secondary_color; char *primary_color; char *picture_filename; char *picture_options; gint picture_opacity; gboolean draw_background; char key[200]; gchar *urlkey; char set_default = 0; workspace = wnck_screen_get_active_workspace(screen_cb); workspace_name = wnck_workspace_get_name(workspace); remove_monitors(); #define GET_BACKGROUND_VALUE(client, type, entry, workspace) \ sprintf(key, MULTI_BACKGROUND_GCONF_PATH "/%s/" # entry, workspace); \ urlkey = url_encode(key); \ entry = gconf_client_get_ ## type(client, urlkey, NULL); \ g_free(urlkey); \ if (entry == NULL) { \ entry = default_ ## entry; \ set_default = 1; \ } GET_BACKGROUND_VALUE (client, string, color_shading_type, workspace_name); GET_BACKGROUND_VALUE (client, string, secondary_color, workspace_name); GET_BACKGROUND_VALUE (client, string, primary_color, workspace_name); GET_BACKGROUND_VALUE (client, string, picture_options, workspace_name); GET_BACKGROUND_VALUE (client, string, picture_filename, workspace_name); /* opacity */ if (!set_default) { sprintf(key, MULTI_BACKGROUND_GCONF_PATH "/%s/picture_opacity", workspace_name); urlkey = url_encode(key); picture_opacity = gconf_client_get_int(client, urlkey, NULL); g_free(urlkey); } else { picture_opacity = default_picture_opacity; } /* draw_background */ if (!set_default) { sprintf(key, MULTI_BACKGROUND_GCONF_PATH "/%s/draw_background", workspace_name); urlkey = url_encode(key); draw_background = gconf_client_get_bool(client, urlkey, NULL); g_free(urlkey); } else { draw_background = default_draw_background; } #define SET_BACKGROUND_VALUE(client, type, entry, workspace) \ gconf_client_set_ ## type(client, DEFAULT_BACKGROUND_GCONF_PATH "/" # entry, entry, NULL) SET_BACKGROUND_VALUE (client, string, picture_filename, workspace_name); SET_BACKGROUND_VALUE (client, int, picture_opacity, workspace_name); SET_BACKGROUND_VALUE (client, string, picture_options, workspace_name); SET_BACKGROUND_VALUE (client, bool, draw_background, workspace_name); SET_BACKGROUND_VALUE (client, string, color_shading_type, workspace_name); SET_BACKGROUND_VALUE (client, string, primary_color, workspace_name); SET_BACKGROUND_VALUE (client, string, secondary_color, workspace_name); add_monitors(); }
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; }
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_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 wnck_selector_scroll_event (GtkWidget *widget, GdkEventScroll *event) { WnckSelector *selector; WnckScreen *screen; WnckWorkspace *workspace; GList *windows_list; GList *l; WnckWindow *window; WnckWindow *previous_window; gboolean should_activate_next_window; selector = WNCK_SELECTOR (widget); screen = wnck_selector_get_screen (selector); workspace = wnck_screen_get_active_workspace (screen); windows_list = wnck_screen_get_windows (screen); windows_list = g_list_sort (windows_list, wnck_selector_windows_compare); /* Walk through the list of windows until we find the active one * (considering only those windows on the same workspace). * Then, depending on whether we're scrolling up or down, activate the next * window in the list (if it exists), or the previous one. */ previous_window = NULL; should_activate_next_window = FALSE; for (l = windows_list; l; l = l->next) { window = WNCK_WINDOW (l->data); if (wnck_window_is_skip_tasklist (window)) continue; if (workspace && !wnck_window_is_pinned (window) && wnck_window_get_workspace (window) != workspace) continue; if (should_activate_next_window) { wnck_window_activate_transient (window, event->time); return TRUE; } if (wnck_window_is_active (window)) { switch (event->direction) { case GDK_SCROLL_UP: if (previous_window != NULL) { wnck_window_activate_transient (previous_window, event->time); return TRUE; } break; case GDK_SCROLL_DOWN: should_activate_next_window = TRUE; break; case GDK_SCROLL_LEFT: case GDK_SCROLL_RIGHT: /* We ignore LEFT and RIGHT scroll events. */ break; case GDK_SCROLL_SMOOTH: break; default: g_assert_not_reached (); } } previous_window = window; } return TRUE; }
GtkWidget * dh_base_get_window_on_current_workspace (DhBase *base) { DhBasePriv *priv; g_return_val_if_fail (DH_IS_BASE (base), NULL); priv = GET_PRIVATE (base); if (!priv->windows) { return NULL; } #ifdef GDK_WINDOWING_X11 { WnckWorkspace *workspace; WnckScreen *screen; GtkWidget *window; GList *windows, *w; GSList *l; gulong xid; pid_t pid; screen = wnck_screen_get (0); if (!screen) { return NULL; } workspace = wnck_screen_get_active_workspace (screen); if (!workspace) { return NULL; } xid = 0; pid = getpid (); /* Use _stacked so we can use the one on top. */ windows = wnck_screen_get_windows_stacked (screen); windows = g_list_last (windows); for (w = windows; w; w = w->prev) { if (wnck_window_is_on_workspace (w->data, workspace) && wnck_window_get_pid (w->data) == pid) { xid = wnck_window_get_xid (w->data); break; } } if (!xid) { return NULL; } /* Return the first matching window we have. */ for (l = priv->windows; l; l = l->next) { window = l->data; #if GTK_CHECK_VERSION (2,14,0) if (GDK_WINDOW_XID (gtk_widget_get_window (window)) == xid) { #else if (GDK_WINDOW_XID (window->window) == xid) { #endif return window; } } } return NULL; #else return priv->windows->data; #endif } GtkWidget * dh_base_get_window (DhBase *base) { GtkWidget *window; g_return_val_if_fail (DH_IS_BASE (base), NULL); window = dh_base_get_window_on_current_workspace (base); if (!window) { window = dh_base_new_window (base); gtk_window_present (GTK_WINDOW (window)); } return window; }
/* Do the actual applet initialization */ static void init_wtapplet (PanelApplet *applet) { WTApplet *wtapplet = g_new0 (WTApplet, 1); wtapplet->applet = applet; wtapplet->prefs = loadPreferences(wtapplet); wtapplet->activescreen = wnck_screen_get_default(); wnck_screen_force_update(wtapplet->activescreen); wtapplet->activeworkspace = wnck_screen_get_active_workspace(wtapplet->activescreen); wtapplet->activewindow = wnck_screen_get_active_window(wtapplet->activescreen); wtapplet->umaxedwindow = getUpperMaximized(wtapplet); wtapplet->rootwindow = getRootWindow(wtapplet->activescreen); wtapplet->prefbuilder = gtk_builder_new(); wtapplet->box = GTK_BOX(gtk_hbox_new(FALSE, 0)); wtapplet->icon = GTK_IMAGE(gtk_image_new()); wtapplet->title = GTK_LABEL(gtk_label_new(NULL)); wtapplet->eb_icon = GTK_EVENT_BOX(gtk_event_box_new()); wtapplet->eb_title = GTK_EVENT_BOX(gtk_event_box_new()); wtapplet->orient = panel_applet_get_orient(wtapplet->applet); wtapplet->size_hints = g_new(gint,2); // Widgets to eventboxes, eventboxes to box gtk_widget_set_can_focus(GTK_WIDGET(wtapplet->icon), TRUE); gtk_widget_set_can_focus(GTK_WIDGET(wtapplet->title), TRUE); gtk_container_add (GTK_CONTAINER (wtapplet->eb_icon), GTK_WIDGET(wtapplet->icon)); gtk_container_add (GTK_CONTAINER (wtapplet->eb_title), GTK_WIDGET(wtapplet->title)); gtk_event_box_set_visible_window (wtapplet->eb_icon, FALSE); gtk_event_box_set_visible_window (wtapplet->eb_title, FALSE); // Rotate & place elements setAlignment(wtapplet, (gfloat)wtapplet->prefs->alignment); placeWidgets(wtapplet); // Add box to applet gtk_container_add (GTK_CONTAINER(wtapplet->applet), GTK_WIDGET(wtapplet->box)); // Set event handling (icon & title clicks) g_signal_connect(G_OBJECT (wtapplet->eb_icon), "button-press-event", G_CALLBACK (icon_clicked), wtapplet); g_signal_connect(G_OBJECT (wtapplet->eb_title), "button-press-event", G_CALLBACK (title_clicked), wtapplet); // Global window tracking g_signal_connect(wtapplet->activescreen, "active-window-changed", G_CALLBACK (active_window_changed), wtapplet); // <-- this thing is crashing with compiz !!! g_signal_connect(wtapplet->activescreen, "viewports-changed", G_CALLBACK (viewports_changed), wtapplet); g_signal_connect(wtapplet->activescreen, "active-workspace-changed", G_CALLBACK (active_workspace_changed), wtapplet); g_signal_connect(wtapplet->activescreen, "window-closed", G_CALLBACK (window_closed), wtapplet); g_signal_connect(wtapplet->activescreen, "window-opened", G_CALLBACK (window_opened), wtapplet); // g_signal_connect(G_OBJECT (wtapplet->title), "size-request", G_CALLBACK (applet_title_size_request), wtapplet); g_signal_connect(G_OBJECT (wtapplet->applet), "size-allocate", G_CALLBACK (applet_size_allocate), wtapplet); g_signal_connect(G_OBJECT (wtapplet->applet), "change-background", G_CALLBACK (applet_change_background), wtapplet); g_signal_connect(G_OBJECT (wtapplet->applet), "change-orient", G_CALLBACK (applet_change_orient), wtapplet); g_signal_connect(G_OBJECT (wtapplet->applet), "change-size", G_CALLBACK (applet_change_pixel_size), wtapplet); // Track active window changes wtapplet->active_handler_state = g_signal_connect(G_OBJECT (wtapplet->activewindow), "state-changed", G_CALLBACK (active_window_state_changed), wtapplet); wtapplet->active_handler_name = g_signal_connect(G_OBJECT (wtapplet->activewindow), "name-changed", G_CALLBACK (active_window_nameicon_changed), wtapplet); wtapplet->active_handler_icon = g_signal_connect(G_OBJECT (wtapplet->activewindow), "icon-changed", G_CALLBACK (active_window_nameicon_changed), wtapplet); // Setup applet right-click menu GtkActionGroup *action_group = gtk_action_group_new ("WindowButtons Applet Actions"); gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE); gtk_action_group_add_actions (action_group, windowtitle_menu_actions, G_N_ELEMENTS (windowtitle_menu_actions), wtapplet); panel_applet_setup_menu (applet, windowtitle_menu_items, action_group); panel_applet_set_background_widget (wtapplet->applet, GTK_WIDGET (wtapplet->applet)); // Automatic background update toggleExpand (wtapplet); toggleHidden (wtapplet); // Properly hide or show stuff updateTitle (wtapplet); }