xwm/core: internal windows now create a GtkWindow
[luccawm.git] / xwm / lucca-bin.c
blobea78e424382bcd99263c4ad227f5e61a4df45366
1 /* Copyright (c) 2008 Vincent Povirk
3 Permission is hereby granted, free of charge, to any person
4 obtaining a copy of this software and associated documentation
5 files (the "Software"), to deal in the Software without
6 restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following
10 conditions:
12 The above copyright notice and this permission notice shall be
13 included in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 OTHER DEALINGS IN THE SOFTWARE.
25 #include "lucca-bin.h"
27 /* Implementation of LuccaBin */
29 static GtkWidgetClass* parent_class = NULL;
30 static GtkBinClass* bin_class = NULL;
32 /* method override declarations */
33 static void lucca_bin_realize(GtkWidget* widget);
34 static void lucca_bin_size_request(GtkWidget* widget, GtkRequisition* requisition);
35 static void lucca_bin_size_allocate(GtkWidget* widget, GtkAllocation *allocation);
37 static void lucca_bin_init(GTypeInstance* instance, gpointer g_class) {
38 LuccaBin* bin = LUCCA_BIN(instance);
39 GtkWindow* window = GTK_WINDOW(instance);
41 window->type = GTK_WINDOW_POPUP;
43 bin->dispose_has_run = FALSE;
44 bin->parent_window = NULL;
47 static void lucca_bin_dispose(GObject* obj) {
48 LuccaBin* bin = LUCCA_BIN(obj);
50 if (bin->dispose_has_run) {
51 return;
53 bin->dispose_has_run = TRUE;
55 g_object_unref(bin->parent_window);
57 G_OBJECT_CLASS(parent_class)->dispose(obj);
60 static void lucca_bin_class_init(gpointer g_class, gpointer class_data) {
61 LuccaBinClass* klass = (LuccaBinClass*)g_class;
62 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
63 GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(g_class);
65 /* method overrides */
66 gobject_class->dispose = lucca_bin_dispose;
67 widget_class->realize = lucca_bin_realize;
68 widget_class->size_request = lucca_bin_size_request;
69 widget_class->size_allocate = lucca_bin_size_allocate;
71 parent_class = g_type_class_peek_parent(klass);
73 bin_class = g_type_class_peek(GTK_TYPE_BIN);
76 GType lucca_bin_get_type() {
77 static GType type = 0;
78 if (type == 0) {
79 static const GTypeInfo info = {
80 sizeof (LuccaBinClass),
81 NULL, /* base_init */
82 NULL, /* base_finalize */
83 lucca_bin_class_init,
84 NULL, /* class_finalize */
85 NULL, /* class_data */
86 sizeof (LuccaBin),
87 0, /* n_preallocs */
88 lucca_bin_init
90 type = g_type_register_static (GTK_TYPE_WINDOW, "LuccaBinType", &info, 0);
92 return type;
95 /* method override defintions */
96 static void lucca_bin_realize(GtkWidget* widget) {
97 LuccaBin* bin = LUCCA_BIN(widget);
98 GtkWindow* window = GTK_WINDOW(widget);
99 GdkWindowAttr window_attributes;
100 gint attributes_mask=0;
102 window_attributes.window_type = GDK_WINDOW_TEMP;
104 window_attributes.title = window->title;
105 attributes_mask |= GDK_WA_TITLE;
107 window_attributes.wmclass_name = window->wmclass_name;
108 window_attributes.wmclass_class = window->wmclass_class;
109 attributes_mask |= GDK_WA_WMCLASS;
111 window_attributes.wclass = GDK_INPUT_OUTPUT;
113 window_attributes.visual = gtk_widget_get_visual(widget);
114 window_attributes.colormap = gtk_widget_get_colormap(widget);
115 attributes_mask |= GDK_WA_VISUAL|GDK_WA_COLORMAP;
117 window_attributes.x = widget->allocation.x;
118 window_attributes.y = widget->allocation.y;
119 window_attributes.width = widget->allocation.width;
120 window_attributes.height = widget->allocation.height;
121 attributes_mask |= GDK_WA_X|GDK_WA_Y;
123 window_attributes.event_mask = gtk_widget_get_events (widget);
124 window_attributes.event_mask |= GDK_EXPOSURE_MASK|GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK|GDK_ENTER_NOTIFY_MASK|GDK_LEAVE_NOTIFY_MASK|GDK_FOCUS_CHANGE_MASK|GDK_STRUCTURE_MASK; /* GtkWindows set these events; I have no idea why */
126 window_attributes.override_redirect = TRUE;
127 attributes_mask |= GDK_WA_NOREDIR;
129 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
131 widget->window = gdk_window_new(bin->parent_window, &window_attributes, attributes_mask);
133 gdk_window_set_user_data(widget->window, bin);
135 widget->style = gtk_style_attach(widget->style, widget->window);
136 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
139 static void lucca_bin_size_request(GtkWidget* widget, GtkRequisition* requisition) {
140 requisition->width = widget->allocation.width;
141 requisition->height = widget->allocation.height;
144 static void _size_allocate(LuccaBin* bin) {
145 GtkBin* gtkbin = GTK_BIN(bin);
146 GtkWidget* widget = GTK_WIDGET(bin);
147 GtkAllocation child_allocation;
149 child_allocation.x = 0;
150 child_allocation.y = 0;
151 child_allocation.width = widget->allocation.width;
152 child_allocation.height = widget->allocation.height;
154 if (gtkbin->child)
155 gtk_widget_size_allocate(gtkbin->child, &child_allocation);
158 static void lucca_bin_size_allocate(GtkWidget* widget, GtkAllocation *allocation) {
159 LuccaBin* bin = LUCCA_BIN(widget);
161 widget->allocation = *allocation;
163 _size_allocate(bin);
166 void lucca_bin_set_parent(LuccaBin* bin, GdkWindow* parent) {
167 GtkWidget* widget = GTK_WIDGET(bin);
168 gboolean remap=FALSE;
170 if (bin->parent_window)
171 g_object_unref(bin->parent_window);
172 bin->parent_window = g_object_ref(parent);
174 if (GTK_WIDGET_REALIZED(widget)) {
175 if (GTK_WIDGET_MAPPED(widget)) {
176 gtk_widget_unmap(widget);
177 remap = TRUE;
180 gdk_window_reparent(widget->window, bin->parent_window, widget->allocation.x, widget->allocation.y);
182 if (remap) {
183 gtk_widget_map(widget);
188 void lucca_bin_move_resize(LuccaBin* bin, gint x, gint y, gint width, gint height) {
189 GtkWidget* widget = GTK_WIDGET(bin);
191 widget->allocation.x = x;
192 widget->allocation.y = y;
193 widget->allocation.width = width;
194 widget->allocation.height = height;
196 if (GTK_WIDGET_REALIZED(widget)) {
197 gdk_window_move_resize(widget->window, x, y, width, height);
199 _size_allocate(bin);