1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
4 * Copyright (C) 2018 Sean Davis <bluesabre@xfce.org>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301, USA.
20 *
21 */
22
23 #include <config.h>
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28
29 #include <glib.h>
30 #include <gtk/gtk.h>
31
32 #include "gs-theme-engine.h"
33 #include "gs-theme-engine-marshal.h"
34
35 static void gs_theme_engine_class_init (GSThemeEngineClass *klass);
36 static void gs_theme_engine_init (GSThemeEngine *engine);
37 static void gs_theme_engine_finalize (GObject *object);
38
39 struct GSThemeEnginePrivate {
40 gpointer reserved;
41 };
42
43 static GObjectClass *parent_class = NULL;
44
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GSThemeEngine,gs_theme_engine,GTK_TYPE_DRAWING_AREA)45 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GSThemeEngine, gs_theme_engine, GTK_TYPE_DRAWING_AREA)
46
47 void
48 _gs_theme_engine_profile_log (const char *func,
49 const char *note,
50 const char *format,
51 ...) {
52 va_list args;
53 char *str;
54 char *formatted;
55
56 va_start (args, format);
57 formatted = g_strdup_vprintf (format, args);
58 va_end (args);
59
60 if (func != NULL) {
61 str = g_strdup_printf ("MARK: %s %s: %s %s", g_get_prgname(), func, note ? note : "", formatted);
62 } else {
63 str = g_strdup_printf ("MARK: %s: %s %s", g_get_prgname(), note ? note : "", formatted);
64 }
65
66 g_free (formatted);
67
68 access (str, F_OK);
69 g_free (str);
70 }
71
72 static void
gs_theme_engine_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)73 gs_theme_engine_set_property (GObject *object,
74 guint prop_id,
75 const GValue *value,
76 GParamSpec *pspec) {
77 GS_THEME_ENGINE (object);
78
79 switch (prop_id) {
80 default:
81 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
82 break;
83 }
84 }
85
86 static void
gs_theme_engine_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)87 gs_theme_engine_get_property (GObject *object,
88 guint prop_id,
89 GValue *value,
90 GParamSpec *pspec) {
91 GS_THEME_ENGINE (object);
92
93 switch (prop_id) {
94 default:
95 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
96 break;
97 }
98 }
99
100 static gboolean
gs_theme_engine_real_draw(GtkWidget * widget,cairo_t * cr)101 gs_theme_engine_real_draw (GtkWidget *widget,
102 cairo_t *cr) {
103 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
104 cairo_set_source_rgb (cr, 0, 0, 0);
105 cairo_paint (cr);
106
107 return FALSE;
108 }
109
110 static void
gs_theme_engine_class_init(GSThemeEngineClass * klass)111 gs_theme_engine_class_init (GSThemeEngineClass *klass) {
112 GObjectClass *object_class = G_OBJECT_CLASS (klass);
113 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
114
115 parent_class = g_type_class_peek_parent (klass);
116
117 object_class->finalize = gs_theme_engine_finalize;
118 object_class->get_property = gs_theme_engine_get_property;
119 object_class->set_property = gs_theme_engine_set_property;
120
121 widget_class->draw = gs_theme_engine_real_draw;
122 }
123
124 static void
gs_theme_engine_init(GSThemeEngine * engine)125 gs_theme_engine_init (GSThemeEngine *engine) {
126 engine->priv = gs_theme_engine_get_instance_private (engine);
127 }
128
129 static void
gs_theme_engine_finalize(GObject * object)130 gs_theme_engine_finalize (GObject *object) {
131 GSThemeEngine *engine;
132
133 g_return_if_fail (object != NULL);
134 g_return_if_fail (GS_IS_THEME_ENGINE (object));
135
136 engine = GS_THEME_ENGINE (object);
137
138 g_return_if_fail (engine->priv != NULL);
139
140 G_OBJECT_CLASS (parent_class)->finalize (object);
141 }
142
143 void
gs_theme_engine_get_window_size(GSThemeEngine * engine,int * width,int * height)144 gs_theme_engine_get_window_size (GSThemeEngine *engine,
145 int *width,
146 int *height) {
147 if (width != NULL) {
148 *width = 0;
149 }
150 if (height != NULL) {
151 *height = 0;
152 }
153
154 g_return_if_fail (GS_IS_THEME_ENGINE (engine));
155
156 if (!gtk_widget_get_visible (GTK_WIDGET (engine))) {
157 return;
158 }
159
160 gdk_window_get_geometry (gtk_widget_get_window (GTK_WIDGET (engine)),
161 NULL,
162 NULL,
163 width,
164 height);
165 }
166
167 GdkWindow *
gs_theme_engine_get_window(GSThemeEngine * engine)168 gs_theme_engine_get_window (GSThemeEngine *engine) {
169 g_return_val_if_fail (GS_IS_THEME_ENGINE (engine), NULL);
170
171 return gtk_widget_get_window (GTK_WIDGET (engine));
172 }
173