~mterry/ubuntu/natty/gnome-shell/wip

« back to all changes in this revision

Viewing changes to src/shell-alttab.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-10-12 22:44:00 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091012224400-k91p42yvou07i525
Tags: 2.28.0-0ubuntu1
* New upstream version
* debian/control:
  - updated build requirement
* debian/patches/80_git_change_fix_alt_tab_ressource_usage.patch:
  - git change to fix ressources not being freed on alt-tab

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2
 
 
3
 
#include "shell-alttab.h"
4
 
#include "shell-global.h"
5
 
#include "shell-wm.h"
6
 
#include <mutter-plugin.h>
7
 
 
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
13
 
 * this object.
14
 
 */
15
 
 
16
 
static void shell_alt_tab_handler_interface_init (MetaAltTabHandlerInterface *handler_iface);
17
 
 
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))
21
 
 
22
 
/* Signals */
23
 
enum
24
 
{
25
 
  WINDOW_ADDED,
26
 
  SHOW,
27
 
  DESTROY,
28
 
 
29
 
  LAST_SIGNAL
30
 
};
31
 
static guint signals [LAST_SIGNAL] = { 0 };
32
 
 
33
 
enum 
34
 
{
35
 
  PROP_SELECTED = 1,
36
 
  PROP_SCREEN,
37
 
  PROP_IMMEDIATE
38
 
};
39
 
 
40
 
static void
41
 
shell_alt_tab_handler_init (ShellAltTabHandler *sth)
42
 
{
43
 
  sth->windows = g_ptr_array_new ();
44
 
  sth->selected = -1;
45
 
}
46
 
 
47
 
static void
48
 
shell_alt_tab_handler_constructed (GObject *object)
49
 
{
50
 
  ShellGlobal *global = shell_global_get ();
51
 
  ShellWM *wm;
52
 
 
53
 
  g_object_get (G_OBJECT (global), "window-manager", &wm, NULL);
54
 
  _shell_wm_begin_alt_tab (wm, SHELL_ALT_TAB_HANDLER (object));
55
 
  g_object_unref (wm);
56
 
}
57
 
 
58
 
static void
59
 
shell_alt_tab_handler_set_property (GObject      *object,
60
 
                                    guint         prop_id,
61
 
                                    const GValue *value,
62
 
                                    GParamSpec   *pspec)
63
 
{
64
 
  ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (object);
65
 
 
66
 
  switch (prop_id)
67
 
    {
68
 
    case PROP_SCREEN:
69
 
      /* We don't care */
70
 
      break;
71
 
    case PROP_IMMEDIATE:
72
 
      sth->immediate_mode = g_value_get_boolean (value);
73
 
      break;
74
 
    default:
75
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
76
 
      break;
77
 
    }
78
 
}
79
 
 
80
 
static void
81
 
shell_alt_tab_handler_get_property (GObject      *object,
82
 
                                    guint         prop_id,
83
 
                                    GValue       *value,
84
 
                                    GParamSpec   *pspec)
85
 
{
86
 
  ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (object);
87
 
 
88
 
  switch (prop_id)
89
 
    {
90
 
    case PROP_SELECTED:
91
 
      g_value_set_int (value, sth->selected);
92
 
      break;
93
 
    default:
94
 
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
95
 
      break;
96
 
    }
97
 
}
98
 
 
99
 
static void
100
 
shell_alt_tab_handler_finalize (GObject *object)
101
 
{
102
 
  ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (object);
103
 
 
104
 
  g_ptr_array_free (sth->windows, FALSE);
105
 
 
106
 
  G_OBJECT_CLASS (shell_alt_tab_handler_parent_class)->finalize (object);
107
 
}
108
 
 
109
 
static void
110
 
shell_alt_tab_handler_add_window (MetaAltTabHandler *handler,
111
 
                                  MetaWindow        *window)
112
 
{
113
 
  ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (handler);
114
 
 
115
 
  g_ptr_array_add (sth->windows, window);
116
 
  g_signal_emit (handler, signals[WINDOW_ADDED], 0,
117
 
                 meta_window_get_compositor_private (window));
118
 
}
119
 
 
120
 
static void
121
 
shell_alt_tab_handler_show (MetaAltTabHandler *handler,
122
 
                            MetaWindow        *initial_selection)
123
 
{
124
 
  ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (handler);
125
 
  int i;
126
 
 
127
 
  sth->selected = -1;
128
 
  for (i = 0; i < sth->windows->len; i++)
129
 
    {
130
 
      if (sth->windows->pdata[i] == (gpointer)initial_selection)
131
 
        {
132
 
          sth->selected = i;
133
 
          break;
134
 
        }
135
 
    }
136
 
 
137
 
  g_signal_emit (handler, signals[SHOW], 0, sth->selected);
138
 
}
139
 
 
140
 
static void
141
 
shell_alt_tab_handler_destroy (MetaAltTabHandler *handler)
142
 
{
143
 
  g_signal_emit (handler, signals[DESTROY], 0);
144
 
}
145
 
 
146
 
static void
147
 
shell_alt_tab_handler_forward (MetaAltTabHandler *handler)
148
 
{
149
 
  ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (handler);
150
 
 
151
 
  if (sth->selected == sth->windows->len - 1)
152
 
    sth->selected = 0;
153
 
  else
154
 
    sth->selected++;
155
 
  g_object_notify (G_OBJECT (handler), "selected");
156
 
}
157
 
 
158
 
static void
159
 
shell_alt_tab_handler_backward (MetaAltTabHandler *handler)
160
 
{
161
 
  ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (handler);
162
 
 
163
 
  if (sth->selected == 0)
164
 
    sth->selected = sth->windows->len - 1;
165
 
  else
166
 
    sth->selected--;
167
 
  g_object_notify (G_OBJECT (handler), "selected");
168
 
}
169
 
 
170
 
static MetaWindow *
171
 
shell_alt_tab_handler_get_selected (MetaAltTabHandler *handler)
172
 
{
173
 
  ShellAltTabHandler *sth = SHELL_ALT_TAB_HANDLER (handler);
174
 
 
175
 
  if (sth->selected > -1)
176
 
    return sth->windows->pdata[sth->selected];
177
 
  else
178
 
    return NULL;
179
 
}
180
 
 
181
 
static void
182
 
shell_alt_tab_handler_class_init (ShellAltTabHandlerClass *klass)
183
 
{
184
 
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
185
 
 
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;
190
 
 
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,
194
 
                                   PROP_SELECTED,
195
 
                                   g_param_spec_int ("selected",
196
 
                                                     "Selected",
197
 
                                                     "Selected window",
198
 
                                                     -1, G_MAXINT, -1,
199
 
                                                     G_PARAM_READABLE));
200
 
 
201
 
 
202
 
  signals[WINDOW_ADDED] = g_signal_new ("window-added",
203
 
                                        G_TYPE_FROM_CLASS (klass),
204
 
                                        G_SIGNAL_RUN_LAST,
205
 
                                        0,
206
 
                                        NULL, NULL,
207
 
                                        g_cclosure_marshal_VOID__OBJECT,
208
 
                                        G_TYPE_NONE, 1,
209
 
                                        MUTTER_TYPE_COMP_WINDOW);
210
 
  signals[SHOW] = g_signal_new ("show",
211
 
                                G_TYPE_FROM_CLASS (klass),
212
 
                                G_SIGNAL_RUN_LAST,
213
 
                                0,
214
 
                                NULL, NULL,
215
 
                                g_cclosure_marshal_VOID__INT,
216
 
                                G_TYPE_NONE, 1,
217
 
                                G_TYPE_INT);
218
 
  signals[DESTROY] = g_signal_new ("destroy",
219
 
                                   G_TYPE_FROM_CLASS (klass),
220
 
                                   G_SIGNAL_RUN_LAST,
221
 
                                   0,
222
 
                                   NULL, NULL,
223
 
                                   g_cclosure_marshal_VOID__VOID,
224
 
                                   G_TYPE_NONE, 0);
225
 
}
226
 
 
227
 
static void
228
 
shell_alt_tab_handler_interface_init (MetaAltTabHandlerInterface *handler_iface)
229
 
{
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;
236
 
}