1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3
#include "shell-alttab.h"
4
#include "shell-global.h"
6
#include <mutter-plugin.h>
8
/* Our MetaAltTabHandler implementation; ideally we would implement
9
* this directly from JavaScript, but for now we can't. So we register
10
* this glue class as our MetaAltTabHandler and then when mutter
11
* creates one, we pass it on to ShellWM, which emits a signal to hand
12
* it off to javascript code, which then connects to the signals on
16
static void shell_alt_tab_handler_interface_init (MetaAltTabHandlerInterface *handler_iface);
18
G_DEFINE_TYPE_WITH_CODE (ShellAltTabHandler, shell_alt_tab_handler, G_TYPE_OBJECT,
19
G_IMPLEMENT_INTERFACE (META_TYPE_ALT_TAB_HANDLER,
20
shell_alt_tab_handler_interface_init))
31
static guint signals [LAST_SIGNAL] = { 0 };
41
shell_alt_tab_handler_init (ShellAltTabHandler *sth)
43
sth->windows = g_ptr_array_new ();
48
shell_alt_tab_handler_constructed (GObject *object)
50
ShellGlobal *global = shell_global_get ();
53
g_object_get (G_OBJECT (global), "window-manager", &wm, NULL);
54
_shell_wm_begin_alt_tab (wm, SHELL_ALT_TAB_HANDLER (object));
59
shell_alt_tab_handler_set_property (GObject *object,
64
ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (object);
72
sth->immediate_mode = g_value_get_boolean (value);
75
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
81
shell_alt_tab_handler_get_property (GObject *object,
86
ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (object);
91
g_value_set_int (value, sth->selected);
94
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
100
shell_alt_tab_handler_finalize (GObject *object)
102
ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (object);
104
g_ptr_array_free (sth->windows, FALSE);
106
G_OBJECT_CLASS (shell_alt_tab_handler_parent_class)->finalize (object);
110
shell_alt_tab_handler_add_window (MetaAltTabHandler *handler,
113
ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (handler);
115
g_ptr_array_add (sth->windows, window);
116
g_signal_emit (handler, signals[WINDOW_ADDED], 0,
117
meta_window_get_compositor_private (window));
121
shell_alt_tab_handler_show (MetaAltTabHandler *handler,
122
MetaWindow *initial_selection)
124
ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (handler);
128
for (i = 0; i < sth->windows->len; i++)
130
if (sth->windows->pdata[i] == (gpointer)initial_selection)
137
g_signal_emit (handler, signals[SHOW], 0, sth->selected);
141
shell_alt_tab_handler_destroy (MetaAltTabHandler *handler)
143
g_signal_emit (handler, signals[DESTROY], 0);
147
shell_alt_tab_handler_forward (MetaAltTabHandler *handler)
149
ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (handler);
151
if (sth->selected == sth->windows->len - 1)
155
g_object_notify (G_OBJECT (handler), "selected");
159
shell_alt_tab_handler_backward (MetaAltTabHandler *handler)
161
ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (handler);
163
if (sth->selected == 0)
164
sth->selected = sth->windows->len - 1;
167
g_object_notify (G_OBJECT (handler), "selected");
171
shell_alt_tab_handler_get_selected (MetaAltTabHandler *handler)
173
ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (handler);
175
if (sth->selected > -1)
176
return sth->windows->pdata[sth->selected];
182
shell_alt_tab_handler_class_init (ShellAltTabHandlerClass *klass)
184
GObjectClass *object_class = G_OBJECT_CLASS (klass);
186
object_class->constructed = shell_alt_tab_handler_constructed;
187
object_class->set_property = shell_alt_tab_handler_set_property;
188
object_class->get_property = shell_alt_tab_handler_get_property;
189
object_class->finalize = shell_alt_tab_handler_finalize;
191
g_object_class_override_property (object_class, PROP_SCREEN, "screen");
192
g_object_class_override_property (object_class, PROP_IMMEDIATE, "immediate");
193
g_object_class_install_property (object_class,
195
g_param_spec_int ("selected",
202
signals[WINDOW_ADDED] = g_signal_new ("window-added",
203
G_TYPE_FROM_CLASS (klass),
207
g_cclosure_marshal_VOID__OBJECT,
209
MUTTER_TYPE_COMP_WINDOW);
210
signals[SHOW] = g_signal_new ("show",
211
G_TYPE_FROM_CLASS (klass),
215
g_cclosure_marshal_VOID__INT,
218
signals[DESTROY] = g_signal_new ("destroy",
219
G_TYPE_FROM_CLASS (klass),
223
g_cclosure_marshal_VOID__VOID,
228
shell_alt_tab_handler_interface_init (MetaAltTabHandlerInterface *handler_iface)
230
handler_iface->add_window = shell_alt_tab_handler_add_window;
231
handler_iface->show = shell_alt_tab_handler_show;
232
handler_iface->destroy = shell_alt_tab_handler_destroy;
233
handler_iface->forward = shell_alt_tab_handler_forward;
234
handler_iface->backward = shell_alt_tab_handler_backward;
235
handler_iface->get_selected = shell_alt_tab_handler_get_selected;