Better error message when defaults file is missing.
[xfwm4.git] / src / poswin.c
blobeee9e4c1ccc24b3cf4c8b28d778066e1fb67e716
1 /* $Id$
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 xfwm4 - (c) 2002-2007 Olivier Fourdan
18 based on a patch from Joshua Blanton <jblanton@irg.cs.ohiou.edu>
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
25 #include <glib.h>
26 #include <gdk/gdk.h>
27 #include <gdk/gdkx.h>
28 #include <gtk/gtk.h>
29 #include <libxfce4util/libxfce4util.h>
31 #include "client.h"
32 #include "frame.h"
33 #include "poswin.h"
35 Poswin *
36 poswinCreate (GdkScreen *gscr)
38 Poswin *poswin;
39 GtkWidget *frame;
41 poswin = g_new (Poswin, 1);
43 poswin->window = gtk_window_new (GTK_WINDOW_POPUP);
44 gtk_window_set_screen (GTK_WINDOW (poswin->window), gscr);
45 gtk_container_set_border_width (GTK_CONTAINER (poswin->window), 0);
46 gtk_window_set_resizable (GTK_WINDOW (poswin->window), TRUE);
48 frame = gtk_frame_new (NULL);
49 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
50 gtk_container_set_border_width (GTK_CONTAINER (frame), 0);
51 gtk_container_add (GTK_CONTAINER (poswin->window), frame);
53 poswin->label = gtk_label_new ("");
54 gtk_misc_set_alignment (GTK_MISC (poswin->label), 0.5, 0.5);
55 gtk_misc_set_padding (GTK_MISC (poswin->label), 3, 3);
56 gtk_widget_show (poswin->label);
57 gtk_container_add(GTK_CONTAINER(frame), poswin->label);
58 gtk_widget_show_all (frame);
60 return poswin;
63 void
64 poswinSetPosition (Poswin * poswin, Client *c)
66 /* 32 is enough for (NNNNNxNNNNN) @ (-NNNNN,-NNNNN) */
67 gchar label[32];
68 gint x, y, px, py, pw, ph;
69 gint wsize, hsize;
71 g_return_if_fail (poswin != NULL);
72 g_return_if_fail (c != NULL);
73 g_return_if_fail (c->size->width_inc != 0);
74 g_return_if_fail (c->size->height_inc != 0);
76 x = frameX (c);
77 y = frameY (c);
79 wsize = (c->width - c->size->base_width) / c->size->width_inc;
80 hsize = (c->height - c->size->base_height) / c->size->height_inc;
82 if (wsize < 0)
84 wsize = 0;
86 if (hsize < 0)
88 hsize = 0;
91 #ifdef SHOW_POSITION
92 g_snprintf (label, 32, "(%dx%d) @ (%i,%i)", wsize, hsize, x, y);
93 #else
94 g_snprintf (label, 32, "(%dx%d)", wsize, hsize);
95 #endif
96 gtk_label_set_text (GTK_LABEL (poswin->label), label);
97 gtk_widget_queue_draw (poswin->window);
98 gtk_window_get_size (GTK_WINDOW (poswin->window), &pw, &ph);
99 px = x + (frameWidth (c) - pw) / 2;
100 py = y + (frameHeight (c) - ph) / 2;
101 if (GTK_WIDGET_REALIZED (poswin->window))
103 gdk_window_move_resize (poswin->window->window, px, py, pw, ph);
105 else
107 gtk_window_move (GTK_WINDOW (poswin->window), px, py);
111 void
112 poswinDestroy (Poswin * poswin)
114 g_return_if_fail (poswin != NULL);
116 gtk_widget_destroy (poswin->window);
119 void
120 poswinShow (Poswin * poswin)
122 g_return_if_fail (poswin != NULL);
124 gtk_widget_show (poswin->window);
127 void
128 poswinHide(Poswin * poswin)
130 g_return_if_fail (poswin != NULL);
132 gtk_widget_hide (poswin->window);