From 1d30abd98ef8d52d6594dc9217618231d00e20e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberts=20Muktup=C4=81vels?= Date: Sat, 4 Oct 2014 02:23:17 +0300 Subject: select-workspace.c: update --- src/ui/select-workspace.c | 135 ++++++++++++++++++++++++++++++---------------- src/ui/select-workspace.h | 29 +++++----- src/ui/tabpopup.c | 53 ++---------------- 3 files changed, 108 insertions(+), 109 deletions(-) diff --git a/src/ui/select-workspace.c b/src/ui/select-workspace.c index 453465db..70b7555a 100644 --- a/src/ui/select-workspace.c +++ b/src/ui/select-workspace.c @@ -1,7 +1,5 @@ /* -*- 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. @@ -31,49 +29,13 @@ #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) +struct _MetaSelectWorkspacePrivate { - 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; -} + MetaWorkspace *workspace; + gboolean selected; +}; -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; -} +G_DEFINE_TYPE_WITH_PRIVATE (MetaSelectWorkspace, meta_select_workspace, GTK_TYPE_DRAWING_AREA); /** * meta_convert_meta_to_wnck() converts a MetaWindow to a @@ -113,14 +75,16 @@ static gboolean meta_select_workspace_draw (GtkWidget *widget, cairo_t *cr) { + MetaSelectWorkspace *select; MetaWorkspace *workspace; WnckWindowDisplayInfo *windows; GtkAllocation allocation; int i, n_windows; GList *tmp, *list; - workspace = META_SELECT_WORKSPACE (widget)->workspace; - + select = META_SELECT_WORKSPACE (widget); + workspace = select->priv->workspace; + list = meta_stack_list_windows (workspace->screen->stack, workspace); n_windows = g_list_length (list); windows = g_new (WnckWindowDisplayInfo, n_windows); @@ -171,7 +135,7 @@ meta_select_workspace_draw (GtkWidget *widget, g_free (windows); - if (META_SELECT_WORKSPACE (widget)->selected) + if (select->priv->selected) { GtkStyleContext *context; GdkRGBA color; @@ -195,3 +159,82 @@ meta_select_workspace_draw (GtkWidget *widget, return TRUE; } + +static void +meta_select_workspace_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width) +{ + GTK_WIDGET_CLASS (meta_select_workspace_parent_class)->get_preferred_width (widget, + minimum_width, + natural_width); + + *minimum_width += SELECT_OUTLINE_WIDTH * 2; + *natural_width += SELECT_OUTLINE_WIDTH * 2; +} + +static void +meta_select_workspace_get_preferred_height (GtkWidget *widget, + gint *minimum_height, + gint *natural_height) +{ + GTK_WIDGET_CLASS (meta_select_workspace_parent_class)->get_preferred_height (widget, + minimum_height, + natural_height); + + *minimum_height += SELECT_OUTLINE_WIDTH * 2; + *natural_height += SELECT_OUTLINE_WIDTH * 2; +} + +static void +meta_select_workspace_init (MetaSelectWorkspace *workspace) +{ + workspace->priv = meta_select_workspace_get_instance_private (workspace); +} + +static void +meta_select_workspace_class_init (MetaSelectWorkspaceClass *class) +{ + GtkWidgetClass *widget_class; + + widget_class = GTK_WIDGET_CLASS (class); + + widget_class->draw = meta_select_workspace_draw; + widget_class->get_preferred_width = meta_select_workspace_get_preferred_width; + widget_class->get_preferred_height = meta_select_workspace_get_preferred_height; +} + +GtkWidget * +meta_select_workspace_new (MetaWorkspace *workspace) +{ + GtkWidget *widget; + MetaSelectWorkspace *select; + double screen_aspect; + + widget = g_object_new (META_TYPE_SELECT_WORKSPACE, NULL); + select = META_SELECT_WORKSPACE (widget); + screen_aspect = (double) workspace->screen->rect.height / + (double) workspace->screen->rect.width; + + gtk_widget_set_size_request (widget, + MINI_WORKSPACE_WIDTH + SELECT_OUTLINE_WIDTH * 2, + MINI_WORKSPACE_WIDTH * screen_aspect + SELECT_OUTLINE_WIDTH * 2); + + select->priv->workspace = workspace; + + return widget; +} + +void +meta_select_workspace_select (MetaSelectWorkspace *workspace) +{ + workspace->priv->selected = TRUE; + gtk_widget_queue_draw (GTK_WIDGET (workspace)); +} + +void +meta_select_workspace_unselect (MetaSelectWorkspace *workspace) +{ + workspace->priv->selected = FALSE; + gtk_widget_queue_draw (GTK_WIDGET (workspace)); +} diff --git a/src/ui/select-workspace.h b/src/ui/select-workspace.h index 6b35d416..d6fd793c 100644 --- a/src/ui/select-workspace.h +++ b/src/ui/select-workspace.h @@ -1,7 +1,5 @@ /* -*- 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. @@ -25,23 +23,23 @@ #define SELECT_WORKSPACE_H #include -/* 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)) +#define META_TYPE_SELECT_WORKSPACE (meta_select_workspace_get_type ()) +#define META_SELECT_WORKSPACE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), META_TYPE_SELECT_WORKSPACE, MetaSelectWorkspace)) +#define META_SELECT_WORKSPACE_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), META_TYPE_SELECT_WORKSPACE, MetaSelectWorkspaceClass)) +#define META_IS_SELECT_WORKSPACE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), META_TYPE_SELECT_WORKSPACE)) +#define META_IS_SELECT_WORKSPACE_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), META_TYPE_SELECT_WORKSPACE)) +#define META_SELECT_WORKSPACE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), META_TYPE_SELECT_WORKSPACE, MetaSelectWorkspaceClass)) -typedef struct _MetaSelectWorkspace MetaSelectWorkspace; -typedef struct _MetaSelectWorkspaceClass MetaSelectWorkspaceClass; +typedef struct _MetaSelectWorkspace MetaSelectWorkspace; +typedef struct _MetaSelectWorkspaceClass MetaSelectWorkspaceClass; +typedef struct _MetaSelectWorkspacePrivate MetaSelectWorkspacePrivate; struct _MetaSelectWorkspace { - GtkDrawingArea parent_instance; - MetaWorkspace *workspace; - guint selected : 1; + GtkDrawingArea parent; + MetaSelectWorkspacePrivate *priv; }; struct _MetaSelectWorkspaceClass @@ -49,6 +47,9 @@ struct _MetaSelectWorkspaceClass GtkDrawingAreaClass parent_class; }; -GType meta_select_workspace_get_type (void) G_GNUC_CONST; +GType meta_select_workspace_get_type (void) G_GNUC_CONST; +GtkWidget *meta_select_workspace_new (MetaWorkspace *workspace); +void meta_select_workspace_select (MetaSelectWorkspace *image); +void meta_select_workspace_unselect (MetaSelectWorkspace *image); #endif diff --git a/src/ui/tabpopup.c b/src/ui/tabpopup.c index e9d88156..34a5243d 100644 --- a/src/ui/tabpopup.c +++ b/src/ui/tabpopup.c @@ -31,9 +31,6 @@ #include #include -#define OUTSIDE_SELECT_RECT 2 -#define INSIDE_SELECT_RECT 2 - typedef struct _TabEntry TabEntry; struct _TabEntry @@ -58,10 +55,6 @@ struct _MetaTabPopup gboolean outline; }; -static GtkWidget* selectable_workspace_new (MetaWorkspace *workspace); -static void select_workspace (GtkWidget *widget); -static void unselect_workspace (GtkWidget *widget); - static gboolean outline_window_draw (GtkWidget *widget, cairo_t *cr, @@ -347,7 +340,7 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries, } else { - image = selectable_workspace_new ((MetaWorkspace *) te->key); + image = meta_select_workspace_new ((MetaWorkspace *) te->key); } te->widget = image; @@ -450,15 +443,15 @@ display_entry (MetaTabPopup *popup, if (popup->outline) meta_select_image_unselect (META_SELECT_IMAGE (popup->current_selected_entry->widget)); else - unselect_workspace (popup->current_selected_entry->widget); + meta_select_workspace_unselect (META_SELECT_WORKSPACE (popup->current_selected_entry->widget)); } - + gtk_label_set_markup (GTK_LABEL (popup->label), te->title); if (popup->outline) meta_select_image_select (META_SELECT_IMAGE (te->widget)); else - select_workspace (te->widget); + meta_select_workspace_select (META_SELECT_WORKSPACE (te->widget)); if (popup->outline) { @@ -577,41 +570,3 @@ meta_ui_tab_popup_select (MetaTabPopup *popup, tmp = tmp->next; } } - -#define SELECT_OUTLINE_WIDTH 2 -#define MINI_WORKSPACE_WIDTH 48 - -static GtkWidget* -selectable_workspace_new (MetaWorkspace *workspace) -{ - GtkWidget *widget; - double screen_aspect; - - widget = g_object_new (meta_select_workspace_get_type (), NULL); - - screen_aspect = (double) workspace->screen->rect.height / - (double) workspace->screen->rect.width; - - /* account for select rect */ - gtk_widget_set_size_request (widget, - MINI_WORKSPACE_WIDTH + SELECT_OUTLINE_WIDTH * 2, - MINI_WORKSPACE_WIDTH * screen_aspect + SELECT_OUTLINE_WIDTH * 2); - - META_SELECT_WORKSPACE (widget)->workspace = workspace; - - return widget; -} - -static void -select_workspace (GtkWidget *widget) -{ - META_SELECT_WORKSPACE(widget)->selected = TRUE; - gtk_widget_queue_draw (widget); -} - -static void -unselect_workspace (GtkWidget *widget) -{ - META_SELECT_WORKSPACE (widget)->selected = FALSE; - gtk_widget_queue_draw (widget); -} -- cgit v1.2.1