libxapp: Rename XAppDisplay -> XAppMonitorBlanker
Clement Lefebvre
7 years ago
13 | 13 | AM_CFLAGS = $(WARN_CFLAGS) |
14 | 14 | |
15 | 15 | introspection_sources = \ |
16 | xapp-display.c \ | |
16 | xapp-monitor-blanker.c \ | |
17 | 17 | xapp-kbd-layout-controller.c |
18 | 18 | |
19 | 19 | libxapp_la_SOURCES = \ |
34 | 34 | |
35 | 35 | libxappdir = $(includedir)/xapp/libxapp |
36 | 36 | libxapp_HEADERS = \ |
37 | xapp-display.h \ | |
37 | xapp-monitor-blanker.h \ | |
38 | 38 | xapp-kbd-layout-controller.h |
39 | 39 | |
40 | 40 | -include $(INTROSPECTION_MAKEFILE) |
0 | ||
1 | #include <config.h> | |
2 | ||
3 | #include <stdio.h> | |
4 | #include <stdlib.h> | |
5 | #include <string.h> | |
6 | ||
7 | #include <gdk/gdkx.h> | |
8 | #include <gtk/gtk.h> | |
9 | ||
10 | #include <glib/gi18n-lib.h> | |
11 | ||
12 | #include "xapp-display.h" | |
13 | ||
14 | struct _XAppDisplayPrivate | |
15 | { | |
16 | int num_outputs; | |
17 | gboolean blanked; | |
18 | GtkWidget **windows; | |
19 | }; | |
20 | ||
21 | G_DEFINE_TYPE (XAppDisplay, xapp_display, G_TYPE_OBJECT); | |
22 | ||
23 | GtkWidget *create_blanking_window (GdkScreen *screen, | |
24 | int monitor); | |
25 | ||
26 | static void | |
27 | xapp_display_init (XAppDisplay *self) | |
28 | { | |
29 | self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, XAPP_TYPE_DISPLAY, XAppDisplayPrivate); | |
30 | self->priv->num_outputs = 0; | |
31 | self->priv->blanked = FALSE; | |
32 | self->priv->windows = NULL; | |
33 | } | |
34 | ||
35 | static void | |
36 | xapp_display_finalize (GObject *object) | |
37 | { | |
38 | XAppDisplay *self = XAPP_DISPLAY (object); | |
39 | ||
40 | if (self->priv->windows != NULL) | |
41 | { | |
42 | xapp_display_unblank_monitors (XAPP_DISPLAY(self)); | |
43 | g_free (self->priv->windows); | |
44 | } | |
45 | ||
46 | G_OBJECT_CLASS (xapp_display_parent_class)->finalize (object); | |
47 | } | |
48 | ||
49 | static void | |
50 | xapp_display_class_init (XAppDisplayClass *klass) | |
51 | { | |
52 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | |
53 | ||
54 | gobject_class->finalize = xapp_display_finalize; | |
55 | ||
56 | g_type_class_add_private (gobject_class, sizeof (XAppDisplayPrivate)); | |
57 | } | |
58 | ||
59 | XAppDisplay * | |
60 | xapp_display_new (void) | |
61 | { | |
62 | return g_object_new (XAPP_TYPE_DISPLAY, NULL); | |
63 | } | |
64 | ||
65 | GtkWidget * | |
66 | create_blanking_window (GdkScreen *screen, | |
67 | int monitor) | |
68 | { | |
69 | GdkRectangle fullscreen; | |
70 | GtkWidget *window; | |
71 | GtkStyleContext *context; | |
72 | GtkCssProvider *provider; | |
73 | ||
74 | gdk_screen_get_monitor_geometry(screen, monitor, &fullscreen); | |
75 | ||
76 | window = gtk_window_new (GTK_WINDOW_POPUP); | |
77 | gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), TRUE); | |
78 | gtk_window_set_skip_pager_hint (GTK_WINDOW (window), TRUE); | |
79 | gtk_window_resize (GTK_WINDOW (window), fullscreen.width, fullscreen.height); | |
80 | gtk_window_move (GTK_WINDOW (window), fullscreen.x, fullscreen.y); | |
81 | gtk_widget_set_visible (window, TRUE); | |
82 | ||
83 | context = gtk_widget_get_style_context (GTK_WIDGET (window)); | |
84 | gtk_style_context_add_class (context, "xapp-blanking-window"); | |
85 | provider = gtk_css_provider_new (); | |
86 | gtk_css_provider_load_from_data (provider, | |
87 | ".xapp-blanking-window { background-color: rgb(0, 0, 0); }", | |
88 | -1, NULL); | |
89 | gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); | |
90 | ||
91 | return window; | |
92 | } | |
93 | ||
94 | void | |
95 | xapp_display_blank_other_monitors (XAppDisplay *self, | |
96 | GtkWindow *window) | |
97 | { | |
98 | GdkScreen *screen; | |
99 | int active_monitor; | |
100 | int i; | |
101 | ||
102 | g_return_if_fail (XAPP_IS_DISPLAY (self)); | |
103 | ||
104 | if (self->priv->windows != NULL) | |
105 | return; | |
106 | ||
107 | screen = gtk_window_get_screen (window); | |
108 | active_monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (GTK_WIDGET (window))); | |
109 | self->priv->num_outputs = gdk_screen_get_n_monitors (screen); | |
110 | self->priv->windows = g_new (GtkWidget *, self->priv->num_outputs); | |
111 | ||
112 | for (i = 0; i < self->priv->num_outputs; i++) | |
113 | { | |
114 | if (i != active_monitor) | |
115 | { | |
116 | self->priv->windows[i] = create_blanking_window (screen, i); | |
117 | } | |
118 | else | |
119 | { | |
120 | // initialize at NULL so it gets properly skipped when windows get destroyed | |
121 | self->priv->windows[i] = NULL; | |
122 | } | |
123 | } | |
124 | ||
125 | self->priv->blanked = TRUE; | |
126 | } | |
127 | ||
128 | void | |
129 | xapp_display_unblank_monitors (XAppDisplay *self) | |
130 | { | |
131 | int i; | |
132 | g_return_if_fail (XAPP_IS_DISPLAY (self)); | |
133 | ||
134 | if (self->priv->windows == NULL) | |
135 | return; | |
136 | ||
137 | for (i = 0; i < self->priv->num_outputs; i++) | |
138 | { | |
139 | if (self->priv->windows[i] != NULL) | |
140 | { | |
141 | gtk_widget_destroy (self->priv->windows[i]); | |
142 | self->priv->windows[i] = NULL; | |
143 | } | |
144 | } | |
145 | g_free (self->priv->windows); | |
146 | self->priv->windows = NULL; | |
147 | self->priv->blanked = FALSE; | |
148 | } | |
149 | ||
150 | gboolean | |
151 | xapp_display_are_monitors_blanked (XAppDisplay *self) | |
152 | { | |
153 | return self->priv->blanked; | |
154 | } |
0 | #ifndef __XAPP_DISPLAY_H__ | |
1 | #define __XAPP_DISPLAY_H__ | |
2 | ||
3 | #include <stdio.h> | |
4 | #include <gtk/gtk.h> | |
5 | ||
6 | #include <glib-object.h> | |
7 | ||
8 | G_BEGIN_DECLS | |
9 | ||
10 | #define XAPP_TYPE_DISPLAY (xapp_display_get_type ()) | |
11 | #define XAPP_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XAPP_TYPE_DISPLAY, XAppDisplay)) | |
12 | #define XAPP_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XAPP_TYPE_DISPLAY, XAppDisplayClass)) | |
13 | #define XAPP_IS_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XAPP_TYPE_DISPLAY)) | |
14 | #define XAPP_IS_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XAPP_TYPE_DISPLAY)) | |
15 | #define XAPP_DISPLAY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XAPP_TYPE_DISPLAY, XAppDisplayClass)) | |
16 | ||
17 | typedef struct _XAppDisplayPrivate XAppDisplayPrivate; | |
18 | typedef struct _XAppDisplay XAppDisplay; | |
19 | typedef struct _XAppDisplayClass XAppDisplayClass; | |
20 | ||
21 | struct _XAppDisplay | |
22 | { | |
23 | GObject parent_object; | |
24 | ||
25 | XAppDisplayPrivate *priv; | |
26 | }; | |
27 | ||
28 | struct _XAppDisplayClass | |
29 | { | |
30 | GObjectClass parent_class; | |
31 | }; | |
32 | ||
33 | GType xapp_display_get_type (void); | |
34 | XAppDisplay *xapp_display_new (void); | |
35 | void xapp_display_blank_other_monitors (XAppDisplay *self, | |
36 | GtkWindow *window); | |
37 | void xapp_display_unblank_monitors (XAppDisplay *self); | |
38 | gboolean xapp_display_are_monitors_blanked (XAppDisplay *self); | |
39 | ||
40 | G_END_DECLS | |
41 | ||
42 | #endif /* __XAPP_DISPLAY_H__ */ |
0 | ||
1 | #include <config.h> | |
2 | ||
3 | #include <stdio.h> | |
4 | #include <stdlib.h> | |
5 | #include <string.h> | |
6 | ||
7 | #include <gdk/gdkx.h> | |
8 | #include <gtk/gtk.h> | |
9 | ||
10 | #include <glib/gi18n-lib.h> | |
11 | ||
12 | #include "xapp-monitor-blanker.h" | |
13 | ||
14 | struct _XAppMonitorBlankerPrivate | |
15 | { | |
16 | int num_outputs; | |
17 | gboolean blanked; | |
18 | GtkWidget **windows; | |
19 | }; | |
20 | ||
21 | G_DEFINE_TYPE (XAppMonitorBlanker, xapp_monitor_blanker, G_TYPE_OBJECT); | |
22 | ||
23 | GtkWidget *create_blanking_window (GdkScreen *screen, | |
24 | int monitor); | |
25 | ||
26 | static void | |
27 | xapp_monitor_blanker_init (XAppMonitorBlanker *self) | |
28 | { | |
29 | self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, XAPP_TYPE_MONITOR_BLANKER, XAppMonitorBlankerPrivate); | |
30 | self->priv->num_outputs = 0; | |
31 | self->priv->blanked = FALSE; | |
32 | self->priv->windows = NULL; | |
33 | } | |
34 | ||
35 | static void | |
36 | xapp_monitor_blanker_finalize (GObject *object) | |
37 | { | |
38 | XAppMonitorBlanker *self = XAPP_MONITOR_BLANKER (object); | |
39 | ||
40 | if (self->priv->windows != NULL) | |
41 | { | |
42 | xapp_monitor_blanker_unblank_monitors (XAPP_MONITOR_BLANKER(self)); | |
43 | g_free (self->priv->windows); | |
44 | } | |
45 | ||
46 | G_OBJECT_CLASS (xapp_monitor_blanker_parent_class)->finalize (object); | |
47 | } | |
48 | ||
49 | static void | |
50 | xapp_monitor_blanker_class_init (XAppMonitorBlankerClass *klass) | |
51 | { | |
52 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | |
53 | ||
54 | gobject_class->finalize = xapp_monitor_blanker_finalize; | |
55 | ||
56 | g_type_class_add_private (gobject_class, sizeof (XAppMonitorBlankerPrivate)); | |
57 | } | |
58 | ||
59 | XAppMonitorBlanker * | |
60 | xapp_monitor_blanker_new (void) | |
61 | { | |
62 | return g_object_new (XAPP_TYPE_MONITOR_BLANKER, NULL); | |
63 | } | |
64 | ||
65 | GtkWidget * | |
66 | create_blanking_window (GdkScreen *screen, | |
67 | int monitor) | |
68 | { | |
69 | GdkRectangle fullscreen; | |
70 | GtkWidget *window; | |
71 | GtkStyleContext *context; | |
72 | GtkCssProvider *provider; | |
73 | ||
74 | gdk_screen_get_monitor_geometry(screen, monitor, &fullscreen); | |
75 | ||
76 | window = gtk_window_new (GTK_WINDOW_POPUP); | |
77 | gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), TRUE); | |
78 | gtk_window_set_skip_pager_hint (GTK_WINDOW (window), TRUE); | |
79 | gtk_window_resize (GTK_WINDOW (window), fullscreen.width, fullscreen.height); | |
80 | gtk_window_move (GTK_WINDOW (window), fullscreen.x, fullscreen.y); | |
81 | gtk_widget_set_visible (window, TRUE); | |
82 | ||
83 | context = gtk_widget_get_style_context (GTK_WIDGET (window)); | |
84 | gtk_style_context_add_class (context, "xapp-blanking-window"); | |
85 | provider = gtk_css_provider_new (); | |
86 | gtk_css_provider_load_from_data (provider, | |
87 | ".xapp-blanking-window { background-color: rgb(0, 0, 0); }", | |
88 | -1, NULL); | |
89 | gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); | |
90 | ||
91 | return window; | |
92 | } | |
93 | ||
94 | void | |
95 | xapp_monitor_blanker_blank_other_monitors (XAppMonitorBlanker *self, | |
96 | GtkWindow *window) | |
97 | { | |
98 | GdkScreen *screen; | |
99 | int active_monitor; | |
100 | int i; | |
101 | ||
102 | g_return_if_fail (XAPP_IS_MONITOR_BLANKER (self)); | |
103 | ||
104 | if (self->priv->windows != NULL) | |
105 | return; | |
106 | ||
107 | screen = gtk_window_get_screen (window); | |
108 | active_monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (GTK_WIDGET (window))); | |
109 | self->priv->num_outputs = gdk_screen_get_n_monitors (screen); | |
110 | self->priv->windows = g_new (GtkWidget *, self->priv->num_outputs); | |
111 | ||
112 | for (i = 0; i < self->priv->num_outputs; i++) | |
113 | { | |
114 | if (i != active_monitor) | |
115 | { | |
116 | self->priv->windows[i] = create_blanking_window (screen, i); | |
117 | } | |
118 | else | |
119 | { | |
120 | // initialize at NULL so it gets properly skipped when windows get destroyed | |
121 | self->priv->windows[i] = NULL; | |
122 | } | |
123 | } | |
124 | ||
125 | self->priv->blanked = TRUE; | |
126 | } | |
127 | ||
128 | void | |
129 | xapp_monitor_blanker_unblank_monitors (XAppMonitorBlanker *self) | |
130 | { | |
131 | int i; | |
132 | g_return_if_fail (XAPP_IS_MONITOR_BLANKER (self)); | |
133 | ||
134 | if (self->priv->windows == NULL) | |
135 | return; | |
136 | ||
137 | for (i = 0; i < self->priv->num_outputs; i++) | |
138 | { | |
139 | if (self->priv->windows[i] != NULL) | |
140 | { | |
141 | gtk_widget_destroy (self->priv->windows[i]); | |
142 | self->priv->windows[i] = NULL; | |
143 | } | |
144 | } | |
145 | g_free (self->priv->windows); | |
146 | self->priv->windows = NULL; | |
147 | self->priv->blanked = FALSE; | |
148 | } | |
149 | ||
150 | gboolean | |
151 | xapp_monitor_blanker_are_monitors_blanked (XAppMonitorBlanker *self) | |
152 | { | |
153 | return self->priv->blanked; | |
154 | } |
0 | #ifndef __XAPP_MONITOR_BLANKER_H__ | |
1 | #define __XAPP_MONITOR_BLANKER_H__ | |
2 | ||
3 | #include <stdio.h> | |
4 | #include <gtk/gtk.h> | |
5 | ||
6 | #include <glib-object.h> | |
7 | ||
8 | G_BEGIN_DECLS | |
9 | ||
10 | #define XAPP_TYPE_MONITOR_BLANKER (xapp_monitor_blanker_get_type ()) | |
11 | #define XAPP_MONITOR_BLANKER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XAPP_TYPE_MONITOR_BLANKER, XAppMonitorBlanker)) | |
12 | #define XAPP_MONITOR_BLANKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XAPP_TYPE_MONITOR_BLANKER, XAppMonitorBlankerClass)) | |
13 | #define XAPP_IS_MONITOR_BLANKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XAPP_TYPE_MONITOR_BLANKER)) | |
14 | #define XAPP_IS_MONITOR_BLANKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XAPP_TYPE_MONITOR_BLANKER)) | |
15 | #define XAPP_MONITOR_BLANKER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XAPP_TYPE_MONITOR_BLANKER, XAppMonitorBlankerClass)) | |
16 | ||
17 | typedef struct _XAppMonitorBlankerPrivate XAppMonitorBlankerPrivate; | |
18 | typedef struct _XAppMonitorBlanker XAppMonitorBlanker; | |
19 | typedef struct _XAppMonitorBlankerClass XAppMonitorBlankerClass; | |
20 | ||
21 | struct _XAppMonitorBlanker | |
22 | { | |
23 | GObject parent_object; | |
24 | ||
25 | XAppMonitorBlankerPrivate *priv; | |
26 | }; | |
27 | ||
28 | struct _XAppMonitorBlankerClass | |
29 | { | |
30 | GObjectClass parent_class; | |
31 | }; | |
32 | ||
33 | GType xapp_monitor_blanker_get_type (void); | |
34 | XAppMonitorBlanker *xapp_monitor_blanker_new (void); | |
35 | void xapp_monitor_blanker_blank_other_monitors (XAppMonitorBlanker *self, | |
36 | GtkWindow *window); | |
37 | void xapp_monitor_blanker_unblank_monitors (XAppMonitorBlanker *self); | |
38 | gboolean xapp_monitor_blanker_are_monitors_blanked (XAppMonitorBlanker *self); | |
39 | ||
40 | G_END_DECLS | |
41 | ||
42 | #endif /* __XAPP_MONITOR_BLANKER_H__ */ |