summaryrefslogtreecommitdiff
path: root/gtk/gtkwindow.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2001-02-27 20:40:15 +0000
committerHavoc Pennington <hp@src.gnome.org>2001-02-27 20:40:15 +0000
commit75d79abf9801195a0241b02ed7974fafa8278f5c (patch)
tree750b8f34aca36f06e24ff6ec060353d3e785289f /gtk/gtkwindow.c
parentaf03d3855dc4f6eefe713c69dce355de6f26d4ab (diff)
downloadgdk-pixbuf-75d79abf9801195a0241b02ed7974fafa8278f5c.tar.gz
test the window state stuff
2001-02-26 Havoc Pennington <hp@redhat.com> * gtk/testgtk.c: test the window state stuff * gtk/gtkwindow.c (gtk_window_present): new function, makes a window come to the user's attention as if it were just created (gtk_window_iconify): new function (gtk_window_deiconify): new function (gtk_window_stick): new function (gtk_window_unstick): new function (gtk_window_maximize): new function (gtk_window_unmaximize): new function * gtk/gtkwidget.h, gtk/gtkwidget.c: add window_state_event signal * gtk/gtkmain.c (gtk_main_do_event): handle GDK_WINDOW_STATE * gdk/x11/gdkevents-x11.c: create window state events when appropriate (gdk_wmspec_supported): new function * gdk/x11/gdkwindow-x11.c (gdk_window_iconify): handle iconification before showing the window (gdk_window_deiconify): new function (gdk_window_stick): new function (gdk_window_unstick): new function (gdk_window_maximize): new function (gdk_window_unmaximize): new function * gdk/gdkwindow.c: store the window state in the window; change to using the GDK_WINDOW_STATE_WITHDRAWN flag instead of window->mapped. (gdk_window_get_state): return the current window state * gdk/gdkevents.c (gdk_event_get_time): handle GDK_WINDOW_STATE (gdk_event_get_state): handle GDK_WINDOW_STATE (gdk_synthesize_window_state): function to create the window state events * gdk/gdkevents.h (struct _GdkEventWindowState): new type of event, for changes to "window state" such as maximized, sticky, etc. * gdk/x11/gdkwindow-x11.c (gdk_window_focus): new function, focuses a window * gdk/x11/gdkmain-x11.c (_gdk_wmspec_supported): new function, finds out if we support a given WM spec hint
Diffstat (limited to 'gtk/gtkwindow.c')
-rw-r--r--gtk/gtkwindow.c303
1 files changed, 300 insertions, 3 deletions
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 3d87ca252..9b204245e 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -1247,7 +1247,8 @@ static void
gtk_window_map (GtkWidget *widget)
{
GtkWindow *window;
-
+ GdkWindow *toplevel;
+
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_WINDOW (widget));
@@ -1260,7 +1261,28 @@ gtk_window_map (GtkWidget *widget)
!GTK_WIDGET_MAPPED (window->bin.child))
gtk_widget_map (window->bin.child);
+ if (window->frame)
+ toplevel = window->frame;
+ else
+ toplevel = widget->window;
+
+ if (window->maximize_initially)
+ gdk_window_maximize (toplevel);
+ else
+ gdk_window_unmaximize (toplevel);
+
+ if (window->stick_initially)
+ gdk_window_stick (toplevel);
+ else
+ gdk_window_unstick (toplevel);
+
+ if (window->iconify_initially)
+ gdk_window_iconify (toplevel);
+ else
+ gdk_window_deiconify (toplevel);
+
gdk_window_show (widget->window);
+
if (window->frame)
gdk_window_show (window->frame);
}
@@ -1398,7 +1420,8 @@ gtk_window_realize (GtkWidget *widget)
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
if (window->frame)
gtk_style_set_background (widget->style, window->frame, GTK_STATE_NORMAL);
-
+
+ /* This is a bad hack to set the window background. */
gtk_window_paint (widget, NULL);
if (window->transient_parent &&
@@ -1407,7 +1430,6 @@ gtk_window_realize (GtkWidget *widget)
GTK_WIDGET (window->transient_parent)->window);
}
-
static void
gtk_window_unrealize (GtkWidget *widget)
{
@@ -2786,3 +2808,278 @@ gtk_window_set_frame_dimensions (GtkWindow *window,
}
+
+/**
+ * gtk_window_present:
+ * @window: a #GtkWindow
+ *
+ * Presents a window to the user. This may mean raising the window
+ * in the stacking order, deiconifying it, moving it to the current
+ * desktop, and/or giving it the keyboard focus, possibly dependent
+ * on the user's platform, window manager, and preferences.
+ *
+ * If @window is hidden, this function calls gtk_widget_show()
+ * as well.
+ *
+ * This function should be used when the user tries to open a window
+ * that's already open. Say for example the preferences dialog is
+ * currently open, and the user chooses Preferences from the menu
+ * a second time; use gtk_window_present() to move the already-open dialog
+ * where the user can see it.
+ *
+ **/
+void
+gtk_window_present (GtkWindow *window)
+{
+ GtkWidget *widget;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ widget = GTK_WIDGET (window);
+
+ if (GTK_WIDGET_VISIBLE (window))
+ {
+ g_assert (widget->window != NULL);
+
+ gdk_window_show (widget->window);
+
+ /* note that gdk_window_focus() will also move the window to
+ * the current desktop, for WM spec compliant window managers.
+ */
+ gdk_window_focus (widget->window,
+ gtk_get_current_event_time ());
+ }
+ else
+ {
+ gtk_widget_show (widget);
+ }
+}
+
+/**
+ * gtk_window_iconify:
+ * @window: a #GtkWindow
+ *
+ * Asks to iconify @window. Note that you shouldn't assume the window
+ * is definitely iconified afterward, because other entities (e.g. the
+ * user or window manager) could deiconify it again, or there may not
+ * be a window manager in which case iconification isn't possible,
+ * etc. But normally the window will end up iconified. Just don't write
+ * code that crashes if not.
+ *
+ * It's permitted to call this function before showing a window,
+ * in which case the window will be iconified before it ever appears
+ * onscreen.
+ *
+ * You can track iconification via the "window_state_event" signal
+ * on #GtkWidget.
+ *
+ **/
+void
+gtk_window_iconify (GtkWindow *window)
+{
+ GtkWidget *widget;
+ GdkWindow *toplevel;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ widget = GTK_WIDGET (window);
+
+ window->iconify_initially = TRUE;
+
+ if (window->frame)
+ toplevel = window->frame;
+ else
+ toplevel = widget->window;
+
+ if (toplevel != NULL)
+ gdk_window_iconify (toplevel);
+}
+
+/**
+ * gtk_window_deiconify:
+ * @window: a #GtkWindow
+ *
+ * Asks to deiconify @window. Note that you shouldn't assume the
+ * window is definitely deiconified afterward, because other entities
+ * (e.g. the user or window manager) could iconify it again before
+ * your code which assumes deiconification gets to run.
+ *
+ * You can track iconification via the "window_state_event" signal
+ * on #GtkWidget.
+ **/
+void
+gtk_window_deiconify (GtkWindow *window)
+{
+ GtkWidget *widget;
+ GdkWindow *toplevel;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ widget = GTK_WIDGET (window);
+
+ window->iconify_initially = FALSE;
+
+ if (window->frame)
+ toplevel = window->frame;
+ else
+ toplevel = widget->window;
+
+ if (toplevel != NULL)
+ gdk_window_deiconify (toplevel);
+}
+
+/**
+ * gtk_window_stick:
+ * @window: a #GtkWindow
+ *
+ * Asks to stick @window, which means that it will appear on all user
+ * desktops. Note that you shouldn't assume the window is definitely
+ * stuck afterward, because other entities (e.g. the user or window
+ * manager) could unstick it again, and some window managers do not
+ * support sticking windows. But normally the window will end up
+ * stuck. Just don't write code that crashes if not.
+ *
+ * It's permitted to call this function before showing a window.
+ *
+ * You can track stickiness via the "window_state_event" signal
+ * on #GtkWidget.
+ *
+ **/
+void
+gtk_window_stick (GtkWindow *window)
+{
+ GtkWidget *widget;
+ GdkWindow *toplevel;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ widget = GTK_WIDGET (window);
+
+ window->stick_initially = TRUE;
+
+ if (window->frame)
+ toplevel = window->frame;
+ else
+ toplevel = widget->window;
+
+ if (toplevel != NULL)
+ gdk_window_stick (toplevel);
+}
+
+/**
+ * gtk_window_unstick:
+ * @window: a #GtkWindow
+ *
+ * Asks to unstick @window, which means that it will appear on only
+ * one of the user's desktops. Note that you shouldn't assume the
+ * window is definitely unstuck afterward, because other entities
+ * (e.g. the user or window manager) could stick it again. But
+ * normally the window will end up stuck. Just don't write code that
+ * crashes if not.
+ *
+ * You can track stickiness via the "window_state_event" signal
+ * on #GtkWidget.
+ *
+ **/
+void
+gtk_window_unstick (GtkWindow *window)
+{
+ GtkWidget *widget;
+ GdkWindow *toplevel;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ widget = GTK_WIDGET (window);
+
+ window->stick_initially = FALSE;
+
+ if (window->frame)
+ toplevel = window->frame;
+ else
+ toplevel = widget->window;
+
+ if (toplevel != NULL)
+ gdk_window_unstick (toplevel);
+}
+
+/**
+ * gtk_window_maximize:
+ * @window: a #GtkWindow
+ *
+ * Asks to maximize @window, so that it becomes full-screen. Note that
+ * you shouldn't assume the window is definitely maximized afterward,
+ * because other entities (e.g. the user or window manager) could
+ * unmaximize it again, and not all window managers support
+ * maximization. But normally the window will end up maximized. Just
+ * don't write code that crashes if not.
+ *
+ * It's permitted to call this function before showing a window,
+ * in which case the window will be maximized when it appears onscreen
+ * initially.
+ *
+ * You can track maximization via the "window_state_event" signal
+ * on #GtkWidget.
+ *
+ **/
+void
+gtk_window_maximize (GtkWindow *window)
+{
+ GtkWidget *widget;
+ GdkWindow *toplevel;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ widget = GTK_WIDGET (window);
+
+ window->maximize_initially = TRUE;
+
+ if (window->frame)
+ toplevel = window->frame;
+ else
+ toplevel = widget->window;
+
+ if (toplevel != NULL)
+ gdk_window_maximize (toplevel);
+}
+
+/**
+ * gtk_window_unmaximize:
+ * @window: a #GtkWindow
+ *
+ * Asks to unmaximize @window. Note that you shouldn't assume the
+ * window is definitely unmaximized afterward, because other entities
+ * (e.g. the user or window manager) could maximize it again, and not
+ * all window managers honor requests to unmaximize. But normally the
+ * window will end up unmaximized. Just don't write code that crashes
+ * if not.
+ *
+ * You can track maximization via the "window_state_event" signal
+ * on #GtkWidget.
+ *
+ **/
+void
+gtk_window_unmaximize (GtkWindow *window)
+{
+ GtkWidget *widget;
+ GdkWindow *toplevel;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ widget = GTK_WIDGET (window);
+
+ window->maximize_initially = FALSE;
+
+ if (window->frame)
+ toplevel = window->frame;
+ else
+ toplevel = widget->window;
+
+ if (toplevel != NULL)
+ gdk_window_unmaximize (toplevel);
+}
+
+
+
+
+
+