all repos — tint2 @ 8917a4d15b15a06915bf6a4a52d90271675568a9

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

src/button/button.h (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
#ifndef BUTTON_H
#define BUTTON_H

#include <sys/time.h>
#include <pango/pangocairo.h>

#include "area.h"
#include "common.h"
#include "timer.h"

// Architecture:
// Panel panel_config contains an array of Button, each storing all config options and all the state variables.
// Only these run commands.
//
// Tint2 maintains an array of Panels, one for each monitor. Each stores an array of Button which was initially copied
// from panel_config. Each works as a frontend to the corresponding Button in panel_config as backend, using the
// backend's config and state variables.

typedef struct ButtonBackend {
	// Config:
	char *icon_name;
	char *text;
	char *tooltip;
	gboolean centered;
	int max_icon_size;
	gboolean has_font;
	PangoFontDescription *font_desc;
	Color font_color;
	char *lclick_command;
	char *mclick_command;
	char *rclick_command;
	char *uwheel_command;
	char *dwheel_command;
	// paddingxlr = horizontal padding left/right
	// paddingx = horizontal padding between childs
	int paddingxlr, paddingx, paddingy;
	Background *bg;

	// List of Button which are frontends for this backend, one for each panel
	GList *instances;
} ButtonBackend;

typedef struct ButtonFrontend {
	// Frontend state:
	Imlib_Image icon;
	Imlib_Image icon_hover;
	Imlib_Image icon_pressed;
	int icon_load_size;
	int iconx;
	int icony;
	int iconw;
	int iconh;
	int textx;
	int texty;
	int textw;
	int texth;
} ButtonFrontend;

typedef struct Button {
	Area area;
	// All elements have the backend pointer set. However only backend elements have ownership.
	ButtonBackend *backend;
	// Set only for frontend Button items.
	ButtonFrontend *frontend;
} Button;

// Called before the config is read and panel_config/panels are created.
// Afterwards, the config parsing code creates the array of Button in panel_config and populates the configuration fields
// in the backend.
// Probably does nothing.
void default_button();

// Creates a new Button item with only the backend field set. The state is NOT initialized. The config is initialized to
// the default values.
// This will be used by the config code to populate its backedn config fields.
Button *create_button();

void destroy_button(void *obj);

// Called after the config is read and panel_config is populated, but before panels are created.
// Initializes the state of the backend items.
// panel_config.panel_items is used to determine which backend items are enabled. The others should be destroyed and
// removed from panel_config.button_list.
void init_button();

// Called after each on-screen panel is created, with a pointer to the panel.
// Initializes the state of the frontend items. Also adds a pointer to it in backend->instances.
// At this point the Area has not been added yet to the GUI tree, but it will be added right away.
void init_button_panel(void *panel);

// Called just before the panels are destroyed. Afterwards, tint2 exits or restarts and reads the config again.
// Releases all frontends and then all the backends.
// The frontend items are not freed by this function, only their members. The items are Areas which are freed in the
// GUI element tree cleanup function (remove_area).
void cleanup_button();

// Called on draw, obj = pointer to the front-end Button item.
void draw_button(void *obj, cairo_t *c);

// Called on resize, obj = pointer to the front-end Button item.
// Returns 1 if the new size is different than the previous size.
gboolean resize_button(void *obj);

// Called on mouse click event.
void button_action(void *obj, int button, int x, int y);

void button_default_font_changed();
void button_default_icon_theme_changed();

void button_reload_icon(Button *button);

#endif // BUTTON_H