summaryrefslogtreecommitdiff
path: root/libmdock/mdock-widget.c
blob: defca10d9c01d256c2308954cef72c3308983d13 (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
/*
 * Copyright 2015 Javier S. Pedro <dev.git@javispedro.com>
 *
 * This file is part of MDock.
 *
 * MDock 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 3 of the License, or
 * (at your option) any later version.
 *
 * MDock 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MDock.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <gtk/gtk.h>

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

#include "mdock-widget.h"
#include "mdock-item.h"
#include "matcher.h"

struct _MDockWidgetPrivate
{
	WnckScreen *wnck_screen;
	GSequence *groups;
};

G_DEFINE_TYPE(MDockWidget, mdock_widget, GTK_TYPE_BOX)

#define MDOCK_WIDGET_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), MDOCK_TYPE_WIDGET, MDockWidgetPrivate))

static void handle_active_window_changed(MDockWidget *self, WnckWindow *previous_window, WnckScreen *screen)
{

}

static void handle_window_closed(MDockWidget *self, WnckWindow *window, WnckScreen *screen)
{

}

static void handle_window_opened(MDockWidget *self, WnckWindow *window, WnckScreen *screen)
{
	if (wnck_window_is_skip_tasklist(window)) {
		return;
	}
	g_debug("Window opened: %s", wnck_window_get_name(window));
	AppId *appid = app_id_from_window(window);
	g_debug("%s %d %s %s %s", appid->host, appid->uid, appid->executable, appid->wm_class_class, appid->wm_class_name);
	const gchar *desktopid = match_appid_to_desktopid(appid);
	g_debug("desktopid: %s", desktopid);
}

static void mdock_widget_dispose(GObject *obj)
{
	MDockWidget *self = MDOCK_WIDGET(obj);
	if (self->priv->wnck_screen) {
		g_signal_handlers_disconnect_by_data(self->priv->wnck_screen, self);
		self->priv->wnck_screen = NULL;
	}
	G_OBJECT_CLASS(mdock_widget_parent_class)->dispose(obj);
}

static void mdock_widget_class_init(MDockWidgetClass *klass)
{
	// GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);

	GObjectClass *obj_class = G_OBJECT_CLASS(klass);
	obj_class->dispose = mdock_widget_dispose;

	g_type_class_add_private(klass, sizeof(MDockWidgetPrivate));
}

static void mdock_widget_init(MDockWidget *self)
{
	self->priv = MDOCK_WIDGET_GET_PRIVATE(self);

	self->priv->wnck_screen = wnck_screen_get_default();
	g_signal_connect_object(self->priv->wnck_screen, "active-window-changed",
	                 G_CALLBACK(handle_active_window_changed), self, G_CONNECT_SWAPPED);
	g_signal_connect_object(self->priv->wnck_screen, "window-closed",
	                 G_CALLBACK(handle_window_closed), self, G_CONNECT_SWAPPED);
	g_signal_connect_object(self->priv->wnck_screen, "window-opened",
	                 G_CALLBACK(handle_window_opened), self, G_CONNECT_SWAPPED);

	self->priv->groups = g_sequence_new(NULL);

	g_debug("widget init");

	GList *windows = wnck_screen_get_windows_stacked(self->priv->wnck_screen);
	for (GList *l = g_list_first(windows); l; l = g_list_next(l)) {
		g_debug("list");
		WnckWindow *window = l->data;
		handle_window_opened(self, window, self->priv->wnck_screen);
	}
}

GtkWidget *mdock_widget_new(void)
{
	return GTK_WIDGET(g_object_new(MDOCK_TYPE_WIDGET, NULL));
}