1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-
2  *
3  * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
4  * Copyright (C) 2012-2021 MATE Developers
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_finalize   (GObject            *object);
36 
37 struct GSThemeEnginePrivate
38 {
39 	gpointer reserved;
40 };
41 
42 static GObjectClass *parent_class = NULL;
43 
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GSThemeEngine,gs_theme_engine,GTK_TYPE_DRAWING_AREA)44 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GSThemeEngine, gs_theme_engine, GTK_TYPE_DRAWING_AREA)
45 
46 void
47 _gs_theme_engine_profile_log (const char *func,
48                               const char *note,
49                               const char *format,
50                               ...)
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 	{
62 		str = g_strdup_printf ("MARK: %s %s: %s %s", g_get_prgname(), func, note ? note : "", formatted);
63 	}
64 	else
65 	{
66 		str = g_strdup_printf ("MARK: %s: %s %s", g_get_prgname(), note ? note : "", formatted);
67 	}
68 
69 	g_free (formatted);
70 
71 	access (str, F_OK);
72 	g_free (str);
73 }
74 
75 static void
gs_theme_engine_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)76 gs_theme_engine_set_property (GObject            *object,
77                               guint               prop_id,
78                               const GValue       *value,
79                               GParamSpec         *pspec)
80 {
81 	GS_THEME_ENGINE (object);
82 
83 	switch (prop_id)
84 	{
85 	default:
86 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
87 		break;
88 	}
89 }
90 
91 static void
gs_theme_engine_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)92 gs_theme_engine_get_property (GObject            *object,
93                               guint               prop_id,
94                               GValue             *value,
95                               GParamSpec         *pspec)
96 {
97 	GS_THEME_ENGINE (object);
98 
99 	switch (prop_id)
100 	{
101 	default:
102 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
103 		break;
104 	}
105 }
106 
107 static gboolean
gs_theme_engine_real_draw(GtkWidget * widget,cairo_t * cr)108 gs_theme_engine_real_draw (GtkWidget *widget,
109                            cairo_t   *cr)
110 {
111 	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
112 	cairo_set_source_rgb (cr, 0, 0, 0);
113 	cairo_paint (cr);
114 
115 	return FALSE;
116 }
117 
118 static void
gs_theme_engine_class_init(GSThemeEngineClass * klass)119 gs_theme_engine_class_init (GSThemeEngineClass *klass)
120 {
121 	GObjectClass   *object_class = G_OBJECT_CLASS (klass);
122 	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
123 
124 	parent_class = g_type_class_peek_parent (klass);
125 
126 	object_class->finalize = gs_theme_engine_finalize;
127 	object_class->get_property = gs_theme_engine_get_property;
128 	object_class->set_property = gs_theme_engine_set_property;
129 
130 	widget_class->draw = gs_theme_engine_real_draw;
131 }
132 
133 static void
gs_theme_engine_init(GSThemeEngine * engine)134 gs_theme_engine_init (GSThemeEngine *engine)
135 {
136 	engine->priv = gs_theme_engine_get_instance_private (engine);
137 }
138 
139 static void
gs_theme_engine_finalize(GObject * object)140 gs_theme_engine_finalize (GObject *object)
141 {
142 	GSThemeEngine *engine;
143 
144 	g_return_if_fail (object != NULL);
145 	g_return_if_fail (GS_IS_THEME_ENGINE (object));
146 
147 	engine = GS_THEME_ENGINE (object);
148 
149 	g_return_if_fail (engine->priv != NULL);
150 
151 	G_OBJECT_CLASS (parent_class)->finalize (object);
152 }
153 
154 void
gs_theme_engine_get_window_size(GSThemeEngine * engine,int * width,int * height)155 gs_theme_engine_get_window_size (GSThemeEngine *engine,
156                                  int           *width,
157                                  int           *height)
158 {
159 	if (width != NULL)
160 	{
161 		*width = 0;
162 	}
163 	if (height != NULL)
164 	{
165 		*height = 0;
166 	}
167 
168 	g_return_if_fail (GS_IS_THEME_ENGINE (engine));
169 
170 	if (! gtk_widget_get_visible (GTK_WIDGET (engine)))
171 	{
172 		return;
173 	}
174 
175 	gdk_window_get_geometry (gtk_widget_get_window (GTK_WIDGET (engine)),
176 	                         NULL,
177 	                         NULL,
178 	                         width,
179 	                         height);
180 }
181 
182 GdkWindow *
gs_theme_engine_get_window(GSThemeEngine * engine)183 gs_theme_engine_get_window (GSThemeEngine *engine)
184 {
185 	g_return_val_if_fail (GS_IS_THEME_ENGINE (engine), NULL);
186 
187 	return gtk_widget_get_window (GTK_WIDGET (engine));
188 }
189