all repos — tint2 @ d4a67f631b7ddf5d80bdd42f07ec98e47a7e5644

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

src/tint2conf/theme_view.c (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include "theme_view.h"


enum { PROP_PERCENTAGE = 1, PROP_THEME, PROP_SNAPSHOT, };

static gpointer parent_class = NULL;

static void custom_list_init(CustomList *cellprogress);
static void custom_list_class_init(CustomListClass *klass);
static void custom_list_get_property(GObject *object, guint param_id, GValue *value, GParamSpec *pspec);
static void custom_list_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec);
static void custom_list_finalize(GObject *gobject);


// These functions are the heart of our custom cell renderer
static void custom_list_get_size(GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height);
static void custom_list_render(GtkCellRenderer *cell, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, guint flags);



// register our type with the GObject type system if we haven't done so yet.
// Everything else is done in the callbacks.
GType custom_list_get_type()
{
	static GType type = 0;

	if (type)
		return type;

	if (1) {
		static const GTypeInfo cell_info =
		{
			sizeof (CustomListClass),
			NULL,
			NULL,
			(GClassInitFunc)custom_list_class_init,
			NULL,
			NULL,
			sizeof (CustomList),
			0,
			(GInstanceInitFunc)custom_list_init,
		};

		// Derive from GtkCellRenderer
		type = g_type_register_static(GTK_TYPE_CELL_RENDERER, "CustomList", &cell_info, 0);
	}

	return type;
}


// klass initialisation
// - override the parent's functions that we need to implement.
// - declare our property
// - If you want cells that are editable, you need to override 'activate' and 'start_editing'.
static void custom_list_class_init(CustomListClass *klass)
{
	GtkCellRendererClass *cell_class   = GTK_CELL_RENDERER_CLASS(klass);
	GObjectClass         *object_class = G_OBJECT_CLASS(klass);

printf("custom_list_class_init : deb\n");
	parent_class           = g_type_class_peek_parent (klass);

	cell_class->render   = custom_list_render;
	cell_class->get_size = custom_list_get_size;
	object_class->get_property = custom_list_get_property;
	object_class->set_property = custom_list_set_property;
	object_class->finalize = custom_list_finalize;

	// Install our very own properties
	g_object_class_install_property(object_class, PROP_PERCENTAGE, g_param_spec_double("percentage", "Percentage", "The fractional progress to display", 0.0, 1.0, 0.0, G_PARAM_READWRITE));
	g_object_class_install_property(object_class, PROP_THEME, g_param_spec_string("theme", "Theme", "Theme file name", NULL, G_PARAM_READWRITE));
	g_object_class_install_property(object_class, PROP_SNAPSHOT, g_param_spec_string("snapshot", "Snapshot", "Snapshot file name", NULL, G_PARAM_READWRITE));
}


// CustomList renderer initialisation
static void custom_list_init(CustomList *custom_list)
{
	printf("custom_list_init : deb\n");
	// set some default properties of the parent (GtkCellRenderer).
	GTK_CELL_RENDERER(custom_list)->mode = GTK_CELL_RENDERER_MODE_INERT;
	GTK_CELL_RENDERER(custom_list)->xpad = 2;
	GTK_CELL_RENDERER(custom_list)->ypad = 2;
}


static void custom_list_finalize(GObject *object)
{
/*
  CustomList *cellrendererprogress = CUSTOM_LIST(object);
*/

printf("custom_list_finalize\n");
	// Free any dynamically allocated resources here

	(* G_OBJECT_CLASS (parent_class)->finalize) (object);
}


static void custom_list_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec)
{
	CustomList *custom_list = CUSTOM_LIST(object);

	switch (param_id) {
		case PROP_PERCENTAGE:
			printf("custom_list_set_property : PROP_PERCENTAGE\n");
			custom_list->progress = g_value_get_double(value);
			break;

		case PROP_THEME:
			printf("custom_list_set_property : PROP_THEME\n");
			//if (custom_list->nameTheme) g_free(custom_list->nameTheme);
			custom_list->nameTheme = g_strdup(g_value_get_string(value));
			break;

		case PROP_SNAPSHOT:
			printf("custom_list_set_property : PROP_SNAPSHOT\n");
			custom_list->nameSnapshot = g_strdup(g_value_get_string(value));
			break;

		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
			break;
	}
}


static void custom_list_get_property(GObject *object, guint param_id, GValue *value, GParamSpec *psec)
{
	CustomList *custom_list = CUSTOM_LIST(object);

	switch (param_id) {
		case PROP_PERCENTAGE:
			printf("custom_list_get_property : PROP_PERCENTAGE\n");
			g_value_set_double(value, custom_list->progress);
			break;

		case PROP_THEME:
			printf("custom_list_get_property : PROP_THEME\n");
			g_value_set_string(value, g_strdup(custom_list->nameTheme));
			break;

		case PROP_SNAPSHOT:
			printf("custom_list_get_property : PROP_SNAPSHOT\n");
			g_value_set_string(value, g_strdup(custom_list->nameSnapshot));
			break;
			//g_value_set_object (value, (GObject *)priv->image);

		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec);
			break;
	}
}


GtkCellRenderer *custom_list_new()
{
	return g_object_new(CUSTOM_LIST_TYPE, NULL);
}


/***************************************************************************
 *
 *  custom_cell_renderer_progress_get_size: crucial - calculate the size
 *                                          of our cell, taking into account
 *                                          padding and alignment properties
 *                                          of parent.
 *
 ***************************************************************************/

#define FIXED_WIDTH   100
#define FIXED_HEIGHT  20

static void custom_list_get_size(GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height)
{
	gint calc_width;
	gint calc_height;

	calc_width  = (gint) cell->xpad * 2 + FIXED_WIDTH;
	calc_height = (gint) cell->ypad * 2 + FIXED_HEIGHT;

	if (width)
		*width = calc_width;

	if (height)
		*height = calc_height;

	if (cell_area) {
		if (x_offset) {
			*x_offset = cell->xalign * (cell_area->width - calc_width);
			*x_offset = MAX (*x_offset, 0);
		}

		if (y_offset) {
			*y_offset = cell->yalign * (cell_area->height - calc_height);
			*y_offset = MAX (*y_offset, 0);
		}
	}
}


/***************************************************************************
 *
 *  custom_cell_renderer_progress_render: crucial - do the rendering.
 *
 ***************************************************************************/

static void custom_list_render(GtkCellRenderer *cell, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, guint flags)
{
	CustomList *custom_list = CUSTOM_LIST(cell);
	GtkStateType state;
	gint width, height;
	gint x_offset, y_offset;

	//printf("custom_list_render\n");
	custom_list_get_size (cell, widget, cell_area, &x_offset, &y_offset, &width, &height);

	if (GTK_WIDGET_HAS_FOCUS (widget))
		state = GTK_STATE_ACTIVE;
	else
		state = GTK_STATE_NORMAL;

	width  -= cell->xpad*2;
	height -= cell->ypad*2;

	gtk_paint_box (widget->style, window, GTK_STATE_NORMAL, GTK_SHADOW_IN, NULL, widget, "trough", cell_area->x + x_offset + cell->xpad, cell_area->y + y_offset + cell->ypad, width - 1, height - 1);

	gtk_paint_box (widget->style, window, state, GTK_SHADOW_OUT, NULL, widget, "bar", cell_area->x + x_offset + cell->xpad, cell_area->y + y_offset + cell->ypad, width * custom_list->progress, height - 1);
}