desktop-window.c 3.66 KB
Newer Older
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
/*
 * Copyright (C) 2014 Alberts Muktupāvels
 *
 * This program 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.
 *
 * 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/>.
 */

#include <gdk/gdkx.h>
#include <X11/Xatom.h>
#include "desktop-window.h"

struct _DesktopWindowPrivate {
	gulong size_changed_id;
	gulong monitors_changed_id;
};

G_DEFINE_TYPE_WITH_PRIVATE (DesktopWindow, desktop_window, GTK_TYPE_WINDOW);

static void
desktop_window_screen_changed (GdkScreen *screen,
                               gpointer   user_data)
{
	DesktopWindow *window;
	gint           width;
	gint           height;

	window = DESKTOP_WINDOW (user_data);
	width = gdk_screen_get_width (screen);
	height = gdk_screen_get_height (screen);

	g_object_set (window,
	              "width-request", width,
	              "height-request", height,
	              NULL);
}

static void
desktop_window_dispose (GObject *object)
{
	DesktopWindow        *window;
	DesktopWindowPrivate *priv;
	GdkScreen            *screen;

	window = DESKTOP_WINDOW (object);
	priv = window->priv;
	screen = gdk_screen_get_default ();

	if (priv->size_changed_id > 0) {
		g_signal_handler_disconnect (screen, priv->size_changed_id);
		priv->size_changed_id = 0;
	}

	if (priv->monitors_changed_id > 0) {
		g_signal_handler_disconnect (screen, priv->monitors_changed_id);
		priv->monitors_changed_id = 0;
	}

	G_OBJECT_CLASS (desktop_window_parent_class)->dispose (object);
}

static void
desktop_window_map (GtkWidget *widget)
{
	GTK_WIDGET_CLASS (desktop_window_parent_class)->map (widget);

	gdk_window_lower (gtk_widget_get_window (widget));
}

static void
desktop_window_init (DesktopWindow *window)
{
	DesktopWindowPrivate *priv;
	gint                  id;
	GdkScreen            *screen;

	priv = window->priv = desktop_window_get_instance_private (window);
	screen = gdk_screen_get_default ();

	id = g_signal_connect (screen, "monitors-changed",
	                       G_CALLBACK (desktop_window_screen_changed), window);
	priv->monitors_changed_id = id;

	id = g_signal_connect (screen, "size-changed",
	                       G_CALLBACK (desktop_window_screen_changed), window);
	priv->size_changed_id = id;

	desktop_window_screen_changed (screen, window);
}

static void
desktop_window_class_init (DesktopWindowClass *class)
{
	GObjectClass   *object_class;
	GtkWidgetClass *widget_class;

	object_class = G_OBJECT_CLASS (class);
	widget_class = GTK_WIDGET_CLASS (class);

	object_class->dispose = desktop_window_dispose;

	widget_class->map = desktop_window_map;
}

GtkWidget *
desktop_window_new (void)
{
	GObject   *object;
	GtkWidget *widget;
	GtkWindow *window;

	object = g_object_new (DESKTOP_WINDOW_TYPE,
122
	                       "type", GTK_WINDOW_POPUP,
123
	                       "type-hint", GDK_WINDOW_TYPE_HINT_DESKTOP,
124
125
126
127
128
129
130
131
132
133
	                       "decorated", FALSE,
	                       "skip-pager-hint", TRUE,
	                       "skip-taskbar-hint", TRUE,
	                       "resizable", FALSE,
	                       "app-paintable", TRUE,
	                       NULL);
	widget = GTK_WIDGET (object);
	window = GTK_WINDOW (widget);

	gtk_window_set_keep_below (window, TRUE);
134
	gtk_widget_realize (widget);
135
136
137

	return widget;
}