1 | /* testfullscreen.c |
2 | * Copyright (C) 2013 Red Hat |
3 | * Author: Olivier Fourdan <ofourdan@redhat.com> |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public |
16 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | #include "config.h" |
20 | #include <gtk/gtk.h> |
21 | |
22 | static void |
23 | set_fullscreen_monitor_cb (GtkWidget *widget, gpointer user_data) |
24 | { |
25 | GdkFullscreenMode mode = GPOINTER_TO_INT (user_data); |
26 | GdkDisplay *display; |
27 | GdkSurface *surface; |
28 | GdkMonitor *monitor; |
29 | GdkToplevelLayout *layout; |
30 | |
31 | display = gtk_widget_get_display (widget); |
32 | surface = gtk_native_get_surface (self: gtk_widget_get_native (widget)); |
33 | if (mode == GDK_FULLSCREEN_ON_CURRENT_MONITOR) |
34 | monitor = gdk_display_get_monitor_at_surface (display, surface); |
35 | else |
36 | monitor = NULL; |
37 | layout = gdk_toplevel_layout_new (); |
38 | gdk_toplevel_layout_set_resizable (layout, TRUE); |
39 | gdk_toplevel_layout_set_fullscreen (layout, TRUE, monitor); |
40 | gdk_toplevel_present (toplevel: GDK_TOPLEVEL (ptr: surface), layout); |
41 | gdk_toplevel_layout_unref (layout); |
42 | } |
43 | |
44 | static void |
45 | remove_fullscreen_cb (GtkWidget *widget, gpointer user_data) |
46 | { |
47 | GdkSurface *surface; |
48 | GdkToplevelLayout *layout; |
49 | |
50 | surface = gtk_native_get_surface (self: gtk_widget_get_native (widget)); |
51 | layout = gdk_toplevel_layout_new (); |
52 | gdk_toplevel_layout_set_resizable (layout, TRUE); |
53 | gdk_toplevel_layout_set_fullscreen (layout, FALSE, NULL); |
54 | gdk_toplevel_present (toplevel: GDK_TOPLEVEL (ptr: surface), layout); |
55 | gdk_toplevel_layout_unref (layout); |
56 | } |
57 | |
58 | int |
59 | main (int argc, char *argv[]) |
60 | { |
61 | GtkWidget *window, *vbox, *button; |
62 | |
63 | gtk_init (); |
64 | |
65 | window = gtk_window_new (); |
66 | |
67 | vbox = gtk_box_new (orientation: GTK_ORIENTATION_VERTICAL, spacing: 5); |
68 | gtk_widget_set_valign (widget: vbox, align: GTK_ALIGN_CENTER); |
69 | gtk_widget_set_halign (widget: vbox, align: GTK_ALIGN_CENTER); |
70 | gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE); |
71 | gtk_window_set_child (GTK_WINDOW (window), child: vbox); |
72 | |
73 | button = gtk_button_new_with_label (label: "Fullscreen on current monitor" ); |
74 | g_signal_connect (button, "clicked" , G_CALLBACK (set_fullscreen_monitor_cb), GINT_TO_POINTER (GDK_FULLSCREEN_ON_CURRENT_MONITOR)); |
75 | gtk_box_append (GTK_BOX (vbox), child: button); |
76 | |
77 | button = gtk_button_new_with_label (label: "Fullscreen on all monitors" ); |
78 | g_signal_connect (button, "clicked" , G_CALLBACK (set_fullscreen_monitor_cb), GINT_TO_POINTER (GDK_FULLSCREEN_ON_ALL_MONITORS)); |
79 | gtk_box_append (GTK_BOX (vbox), child: button); |
80 | |
81 | button = gtk_button_new_with_label (label: "Un-fullscreen" ); |
82 | g_signal_connect (button, "clicked" , G_CALLBACK (remove_fullscreen_cb), NULL); |
83 | gtk_box_append (GTK_BOX (vbox), child: button); |
84 | |
85 | gtk_widget_show (widget: window); |
86 | |
87 | while (TRUE) |
88 | g_main_context_iteration (NULL, TRUE); |
89 | |
90 | return 0; |
91 | } |
92 | |