summaryrefslogtreecommitdiff
path: root/mate-window-picker-applet/task-list.c
blob: 137534ce7e42133207f20d021fab3b5c000bf511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
 * Copyright (C) 2008 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as 
 * published by the Free Software Foundation.
 *
 * 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/>.
 *
 * Authored by Neil Jagdish Patel <neil.patel@canonical.com>
 *
 */

#include "task-list.h"
#include "task-item.h"

#define WNCK_I_KNOW_THIS_IS_UNSTABLE
#include <libwnck/libwnck.h>

G_DEFINE_TYPE (TaskList, task_list, GTK_TYPE_HBOX);

#define TASK_LIST_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\
  TASK_TYPE_LIST, \
  TaskListPrivate))

struct _TaskListPrivate
{
  WnckScreen *screen;

  gboolean show_all_windows;
};

enum
{
  PROP_0,
  
  PROP_SHOW_ALL_WINDOWS
};

static void
task_list_set_show_all_windows (TaskList *list, gboolean show_all_windows)
{
  TaskListPrivate *priv = list->priv;

  priv->show_all_windows = show_all_windows;

  g_debug ("Show all windows: %s", show_all_windows ? "true" : "false");
}

static void
on_task_item_closed (TaskItem *item,
                     TaskList *list)
{
  gtk_container_remove (GTK_CONTAINER (list),
                        GTK_WIDGET (item));
  gtk_widget_destroy (GTK_WIDGET (item));
}

static void
on_window_opened (WnckScreen *screen,
                  WnckWindow *window,
                  TaskList   *list)
{
  WnckWindowType type;

  g_return_if_fail (TASK_IS_LIST (list));

  type = wnck_window_get_window_type (window);

  if (type == WNCK_WINDOW_DESKTOP
      || type == WNCK_WINDOW_DOCK
      || type == WNCK_WINDOW_SPLASHSCREEN
      || type == WNCK_WINDOW_MENU)
    return;
    
  GtkWidget *item = task_item_new (window);
  
  if (item)
  {
    gtk_box_pack_start (GTK_BOX (list), item, FALSE, FALSE, 0);
    g_signal_connect (TASK_ITEM (item), "task-item-closed",
                      G_CALLBACK (on_task_item_closed), list);
  }
}

/* GObject stuff */
static void
task_list_finalize (GObject *object)
{
  TaskListPrivate *priv;

  priv = TASK_LIST_GET_PRIVATE (object);

  G_OBJECT_CLASS (task_list_parent_class)->finalize (object);
}

static void
task_list_get_property (GObject    *object,
                        guint       prop_id,
                        GValue     *value,
                        GParamSpec *pspec)
{
  TaskList *list = TASK_LIST (object);
  TaskListPrivate *priv;

  g_return_if_fail (TASK_IS_LIST (list));
  priv = list->priv;

  switch (prop_id)
  {
    case PROP_SHOW_ALL_WINDOWS:
      g_value_set_boolean (value, priv->show_all_windows);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  }
}

static void
task_list_set_property (GObject      *object,
                        guint         prop_id,
                        const GValue *value,
                        GParamSpec   *pspec)
{
  TaskList *list = TASK_LIST (object);

  g_return_if_fail (TASK_IS_LIST (list));

  switch (prop_id)
  {
    case PROP_SHOW_ALL_WINDOWS:
      task_list_set_show_all_windows (list, g_value_get_boolean (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  }
}

static void
task_list_class_init (TaskListClass *klass)
{
  GObjectClass        *obj_class = G_OBJECT_CLASS (klass);

  obj_class->finalize = task_list_finalize;
  obj_class->set_property = task_list_set_property;
  obj_class->get_property = task_list_get_property;

  g_object_class_install_property (obj_class,
    PROP_SHOW_ALL_WINDOWS,
    g_param_spec_boolean ("show_all_windows",
                          "Show All Windows",
                          "Show windows from all workspaces",
                          TRUE,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));

  g_type_class_add_private (obj_class, sizeof (TaskListPrivate));
}

static void
task_list_init (TaskList *list)
{
  TaskListPrivate *priv;

  priv = list->priv = TASK_LIST_GET_PRIVATE (list);

  priv->screen = wnck_screen_get_default ();

  gtk_container_set_border_width (GTK_CONTAINER (list), 0);

  g_signal_connect (priv->screen, "window-opened",
                    G_CALLBACK (on_window_opened), list);
}

GtkWidget *
task_list_new (void)

{
  GtkWidget *list = NULL;

  list = g_object_new (TASK_TYPE_LIST, 
                       "homogeneous", FALSE, 
                       "spacing", 0, 
                       NULL);
  
  return list;
}

GtkWidget *
task_list_get_default (void)
{
  static GtkWidget *list = NULL;

  if (!list)
    list = task_list_new ();

  return list;
}

gboolean    
task_list_get_desktop_visible (TaskList *list)
{
  GList *windows, *w;
  gboolean all_minimised = TRUE;

  g_return_val_if_fail (TASK_IS_LIST (list), TRUE);

  windows = wnck_screen_get_windows (list->priv->screen);
  for (w = windows; w; w = w->next)
  {
    WnckWindow *window;
    
    window = w->data;

    if (WNCK_IS_WINDOW (window) && !wnck_window_is_minimized (window))
      all_minimised = FALSE;
  }

  return all_minimised;
}

gboolean
task_list_get_show_all_windows (TaskList *list)
{
  return list->priv->show_all_windows;
}