diff options
author | Alberts Muktupāvels <alberts.muktupavels@gmail.com> | 2014-10-04 02:00:38 +0300 |
---|---|---|
committer | Alberts Muktupāvels <alberts.muktupavels@gmail.com> | 2014-10-04 15:57:25 +0300 |
commit | 6e6466fbe6ab4650c5f0fa097c200cec4e55e9f0 (patch) | |
tree | be32bdf5d5a4aa9faaa996ffda5b4e58cf6f7cd5 | |
parent | 51b9e57dcab716b874c668bdfa9d457fda15f6eb (diff) | |
download | metacity-6e6466fbe6ab4650c5f0fa097c200cec4e55e9f0.tar.gz |
tabpopup.c: split out MetaSelectWorkspace
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ui/select-workspace.c | 197 | ||||
-rw-r--r-- | src/ui/select-workspace.h | 54 | ||||
-rw-r--r-- | src/ui/tabpopup.c | 193 |
4 files changed, 254 insertions, 192 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 465d6375..1562002f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -94,6 +94,8 @@ metacity_SOURCES= \ include/tabpopup.h \ ui/select-image.c \ ui/select-image.h \ + ui/select-workspace.c \ + ui/select-workspace.h \ ui/tile-preview.c \ include/tile-preview.h \ ui/theme-parser.c \ diff --git a/src/ui/select-workspace.c b/src/ui/select-workspace.c new file mode 100644 index 00000000..453465db --- /dev/null +++ b/src/ui/select-workspace.c @@ -0,0 +1,197 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* Metacity popup window thing showing windows you can tab to */ + +/* + * Copyright (C) 2001 Havoc Pennington + * Copyright (C) 2002 Red Hat, Inc. + * Copyright (C) 2005 Elijah Newren + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include <config.h> +#include <gtk/gtk.h> +#include <math.h> +#include "select-workspace.h" +#include "../core/frame-private.h" +#include "draw-workspace.h" + +#define SELECT_OUTLINE_WIDTH 2 +#define MINI_WORKSPACE_WIDTH 48 + +static void meta_select_workspace_class_init (MetaSelectWorkspaceClass *klass); + +static gboolean meta_select_workspace_draw (GtkWidget *widget, + cairo_t *cr); + +GType +meta_select_workspace_get_type (void) +{ + static GType workspace_type = 0; + + if (!workspace_type) + { + static const GTypeInfo workspace_info = + { + sizeof (MetaSelectWorkspaceClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) meta_select_workspace_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (MetaSelectWorkspace), + 16, /* n_preallocs */ + (GInstanceInitFunc) NULL, + }; + + workspace_type = g_type_register_static (GTK_TYPE_DRAWING_AREA, + "MetaSelectWorkspace", + &workspace_info, + 0); + } + + return workspace_type; +} + +static void +meta_select_workspace_class_init (MetaSelectWorkspaceClass *klass) +{ + GtkWidgetClass *widget_class; + + widget_class = GTK_WIDGET_CLASS (klass); + + widget_class->draw = meta_select_workspace_draw; +} + +/** + * meta_convert_meta_to_wnck() converts a MetaWindow to a + * WnckWindowDisplayInfo window that is used to build a thumbnail of a + * workspace. + **/ +static WnckWindowDisplayInfo +meta_convert_meta_to_wnck (MetaWindow *window, MetaScreen *screen) +{ + WnckWindowDisplayInfo wnck_window; + wnck_window.icon = window->icon; + wnck_window.mini_icon = window->mini_icon; + + wnck_window.is_active = FALSE; + if (window == window->display->expected_focus_window) + wnck_window.is_active = TRUE; + + if (window->frame) + { + wnck_window.x = window->frame->rect.x; + wnck_window.y = window->frame->rect.y; + wnck_window.width = window->frame->rect.width; + wnck_window.height = window->frame->rect.height; + } + else + { + wnck_window.x = window->rect.x; + wnck_window.y = window->rect.y; + wnck_window.width = window->rect.width; + wnck_window.height = window->rect.height; + } + return wnck_window; +} + + +static gboolean +meta_select_workspace_draw (GtkWidget *widget, + cairo_t *cr) +{ + MetaWorkspace *workspace; + WnckWindowDisplayInfo *windows; + GtkAllocation allocation; + int i, n_windows; + GList *tmp, *list; + + workspace = META_SELECT_WORKSPACE (widget)->workspace; + + list = meta_stack_list_windows (workspace->screen->stack, workspace); + n_windows = g_list_length (list); + windows = g_new (WnckWindowDisplayInfo, n_windows); + + tmp = list; + i = 0; + while (tmp != NULL) + { + MetaWindow *window; + gboolean ignoreable_sticky; + + window = tmp->data; + + ignoreable_sticky = window->on_all_workspaces && + workspace != workspace->screen->active_workspace; + + if (window->skip_pager || + !meta_window_showing_on_its_workspace (window) || + window->unmaps_pending || + ignoreable_sticky) + { + --n_windows; + } + else + { + windows[i] = meta_convert_meta_to_wnck (window, workspace->screen); + i++; + } + tmp = tmp->next; + } + + g_list_free (list); + + gtk_widget_get_allocation (widget, &allocation); + + wnck_draw_workspace (widget, + cr, + SELECT_OUTLINE_WIDTH, + SELECT_OUTLINE_WIDTH, + allocation.width - SELECT_OUTLINE_WIDTH * 2, + allocation.height - SELECT_OUTLINE_WIDTH * 2, + workspace->screen->rect.width, + workspace->screen->rect.height, + NULL, + (workspace->screen->active_workspace == workspace), + windows, + n_windows); + + g_free (windows); + + if (META_SELECT_WORKSPACE (widget)->selected) + { + GtkStyleContext *context; + GdkRGBA color; + + context = gtk_widget_get_style_context (widget); + + gtk_style_context_set_state (context, + gtk_widget_get_state_flags (widget)); + + gtk_style_context_lookup_color (context, "color", &color); + + cairo_set_line_width (cr, SELECT_OUTLINE_WIDTH); + cairo_set_source_rgb (cr, color.red, color.green, color.blue); + + cairo_rectangle (cr, + SELECT_OUTLINE_WIDTH / 2.0, SELECT_OUTLINE_WIDTH / 2.0, + allocation.width - SELECT_OUTLINE_WIDTH, + allocation.height - SELECT_OUTLINE_WIDTH); + cairo_stroke (cr); + } + + return TRUE; +} diff --git a/src/ui/select-workspace.h b/src/ui/select-workspace.h new file mode 100644 index 00000000..6b35d416 --- /dev/null +++ b/src/ui/select-workspace.h @@ -0,0 +1,54 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ + +/* Metacity popup window thing showing windows you can tab to */ + +/* + * Copyright (C) 2001 Havoc Pennington + * Copyright (C) 2002 Red Hat, Inc. + * Copyright (C) 2005 Elijah Newren + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SELECT_WORKSPACE_H +#define SELECT_WORKSPACE_H + +#include <gtk/gtk.h> +/* FIXME these two includes are 100% broken ... + */ +#include "../core/workspace.h" +#include "../core/frame-private.h" +#include "draw-workspace.h" + +#define META_TYPE_SELECT_WORKSPACE (meta_select_workspace_get_type ()) +#define META_SELECT_WORKSPACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_SELECT_WORKSPACE, MetaSelectWorkspace)) + +typedef struct _MetaSelectWorkspace MetaSelectWorkspace; +typedef struct _MetaSelectWorkspaceClass MetaSelectWorkspaceClass; + +struct _MetaSelectWorkspace +{ + GtkDrawingArea parent_instance; + MetaWorkspace *workspace; + guint selected : 1; +}; + +struct _MetaSelectWorkspaceClass +{ + GtkDrawingAreaClass parent_class; +}; + +GType meta_select_workspace_get_type (void) G_GNUC_CONST; + +#endif diff --git a/src/ui/tabpopup.c b/src/ui/tabpopup.c index 2a72d4cf..e9d88156 100644 --- a/src/ui/tabpopup.c +++ b/src/ui/tabpopup.c @@ -27,11 +27,7 @@ #include "core.h" #include "tabpopup.h" #include "select-image.h" -/* FIXME these two includes are 100% broken ... - */ -#include "../core/workspace.h" -#include "../core/frame-private.h" -#include "draw-workspace.h" +#include "select-workspace.h" #include <gtk/gtk.h> #include <math.h> @@ -582,27 +578,6 @@ meta_ui_tab_popup_select (MetaTabPopup *popup, } } -#define META_TYPE_SELECT_WORKSPACE (meta_select_workspace_get_type ()) -#define META_SELECT_WORKSPACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_SELECT_WORKSPACE, MetaSelectWorkspace)) - -typedef struct _MetaSelectWorkspace MetaSelectWorkspace; -typedef struct _MetaSelectWorkspaceClass MetaSelectWorkspaceClass; - -struct _MetaSelectWorkspace -{ - GtkDrawingArea parent_instance; - MetaWorkspace *workspace; - guint selected : 1; -}; - -struct _MetaSelectWorkspaceClass -{ - GtkDrawingAreaClass parent_class; -}; - - -static GType meta_select_workspace_get_type (void) G_GNUC_CONST; - #define SELECT_OUTLINE_WIDTH 2 #define MINI_WORKSPACE_WIDTH 48 @@ -640,169 +615,3 @@ unselect_workspace (GtkWidget *widget) META_SELECT_WORKSPACE (widget)->selected = FALSE; gtk_widget_queue_draw (widget); } - -static void meta_select_workspace_class_init (MetaSelectWorkspaceClass *klass); - -static gboolean meta_select_workspace_draw (GtkWidget *widget, - cairo_t *cr); - -GType -meta_select_workspace_get_type (void) -{ - static GType workspace_type = 0; - - if (!workspace_type) - { - static const GTypeInfo workspace_info = - { - sizeof (MetaSelectWorkspaceClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) meta_select_workspace_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (MetaSelectWorkspace), - 16, /* n_preallocs */ - (GInstanceInitFunc) NULL, - }; - - workspace_type = g_type_register_static (GTK_TYPE_DRAWING_AREA, - "MetaSelectWorkspace", - &workspace_info, - 0); - } - - return workspace_type; -} - -static void -meta_select_workspace_class_init (MetaSelectWorkspaceClass *klass) -{ - GtkWidgetClass *widget_class; - - widget_class = GTK_WIDGET_CLASS (klass); - - widget_class->draw = meta_select_workspace_draw; -} - -/** - * meta_convert_meta_to_wnck() converts a MetaWindow to a - * WnckWindowDisplayInfo window that is used to build a thumbnail of a - * workspace. - **/ -static WnckWindowDisplayInfo -meta_convert_meta_to_wnck (MetaWindow *window, MetaScreen *screen) -{ - WnckWindowDisplayInfo wnck_window; - wnck_window.icon = window->icon; - wnck_window.mini_icon = window->mini_icon; - - wnck_window.is_active = FALSE; - if (window == window->display->expected_focus_window) - wnck_window.is_active = TRUE; - - if (window->frame) - { - wnck_window.x = window->frame->rect.x; - wnck_window.y = window->frame->rect.y; - wnck_window.width = window->frame->rect.width; - wnck_window.height = window->frame->rect.height; - } - else - { - wnck_window.x = window->rect.x; - wnck_window.y = window->rect.y; - wnck_window.width = window->rect.width; - wnck_window.height = window->rect.height; - } - return wnck_window; -} - - -static gboolean -meta_select_workspace_draw (GtkWidget *widget, - cairo_t *cr) -{ - MetaWorkspace *workspace; - WnckWindowDisplayInfo *windows; - GtkAllocation allocation; - int i, n_windows; - GList *tmp, *list; - - workspace = META_SELECT_WORKSPACE (widget)->workspace; - - list = meta_stack_list_windows (workspace->screen->stack, workspace); - n_windows = g_list_length (list); - windows = g_new (WnckWindowDisplayInfo, n_windows); - - tmp = list; - i = 0; - while (tmp != NULL) - { - MetaWindow *window; - gboolean ignoreable_sticky; - - window = tmp->data; - - ignoreable_sticky = window->on_all_workspaces && - workspace != workspace->screen->active_workspace; - - if (window->skip_pager || - !meta_window_showing_on_its_workspace (window) || - window->unmaps_pending || - ignoreable_sticky) - { - --n_windows; - } - else - { - windows[i] = meta_convert_meta_to_wnck (window, workspace->screen); - i++; - } - tmp = tmp->next; - } - - g_list_free (list); - - gtk_widget_get_allocation (widget, &allocation); - - wnck_draw_workspace (widget, - cr, - SELECT_OUTLINE_WIDTH, - SELECT_OUTLINE_WIDTH, - allocation.width - SELECT_OUTLINE_WIDTH * 2, - allocation.height - SELECT_OUTLINE_WIDTH * 2, - workspace->screen->rect.width, - workspace->screen->rect.height, - NULL, - (workspace->screen->active_workspace == workspace), - windows, - n_windows); - - g_free (windows); - - if (META_SELECT_WORKSPACE (widget)->selected) - { - GtkStyleContext *context; - GdkRGBA color; - - context = gtk_widget_get_style_context (widget); - - gtk_style_context_set_state (context, - gtk_widget_get_state_flags (widget)); - - gtk_style_context_lookup_color (context, "color", &color); - - cairo_set_line_width (cr, SELECT_OUTLINE_WIDTH); - cairo_set_source_rgb (cr, color.red, color.green, color.blue); - - cairo_rectangle (cr, - SELECT_OUTLINE_WIDTH / 2.0, SELECT_OUTLINE_WIDTH / 2.0, - allocation.width - SELECT_OUTLINE_WIDTH, - allocation.height - SELECT_OUTLINE_WIDTH); - cairo_stroke (cr); - } - - return TRUE; -} - |