changed author email
[guish.git] / src / widgets / label.c
blobc8c4df311de704ea3d1aa9c94172d3189f3dc06e
1 /*************************************************************************
2 * Copyright (C) 2024 Francesco Palumbo <phranz.dev@gmail.com>, Naples (Italy)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *************************************************************************/
18 #include "label.h"
19 #include "../dectypes.h"
21 extern GC gc;
22 extern Atom delatom;
23 extern Display* display;
24 extern Window root;
25 extern int screen;
26 extern map_strcol_t* colors;
28 extern map_widloci_t* widlines;
29 extern map_widloci_t* widareas;
30 extern map_widarcssets_t* widarcssets;
31 extern map_widarcssets_t* widarcsareas;
32 extern map_widloci_t* widloci;
33 extern map_widloci_t* widpixels;
34 extern map_widnamedpoints_t* widnamedpoints;
36 static void draw(widget_t* w) {
37 if (w->flags & F_HOVERED && w->flags & F_APPLYHOVER) {
38 XSetWindowBackground(display, w->wid, w->hbg->pixel);
39 XSetForeground(display, gc, w->hfg->pixel);
40 #ifdef ENABLE_IMAGES
41 } else if (w->img) {
42 updateimg(w);
43 #endif
44 } else {
45 XSetWindowBackground(display, w->wid, w->bg->pixel);
46 XSetForeground(display, gc, w->fg->pixel);
48 XSetFont(display, gc, w->fs->fid);
49 XClearWindow(display, w->wid);
50 write_align(w, w->data, w->align, NULL);
51 if (widareas)
52 drawareas(w);
53 if (widarcsareas)
54 drawarcsareas(w);
55 if (widlines)
56 drawlines(w);
57 if (widarcssets)
58 drawarcs(w);
59 if (widloci)
60 drawpoints(w);
61 if (widpixels)
62 drawpixels(w);
63 if (widnamedpoints)
64 drawnamedpoints(w);
67 void label_t_free(label_t* p) {
68 ((widget_t*)p)->free((widget_t*)p);;
69 free(p);
72 label_t* label_t_init(label_t* p, int ww, int hh) {
73 if (!p)
74 return NULL;
75 memset(p, 0, sizeof(label_t));
76 widget_t* w = (widget_t*)p;
77 widget_t_init(w);
79 p->free = label_t_free;
80 w->draw = draw;
82 w->x = 0;
83 w->y = 0;
84 w->w = ww ? ww : 120;
85 w->h = hh ? hh : 40;
86 w->b = 0;
88 colors->get(colors, "lightgray", &w->bg);
89 colors->get(colors, "black", &w->fg);
91 colors->get(colors, "lightgray", &w->pbg);
92 colors->get(colors, "black", &w->pfg);
94 colors->get(colors, "lightgray", &w->hbg);
95 colors->get(colors, "black", &w->hfg);
97 XSetWindowAttributes wa = {0};
99 w->wid = XCreateWindow(display, root, w->x, w->y, w->w, w->h, w->b, DefaultDepth(display, screen), InputOutput, DefaultVisual(display, screen), CWOverrideRedirect, &wa);
101 w->mask = VisibilityChangeMask|ExposureMask|StructureNotifyMask;
102 XSelectInput(display, w->wid, w->mask);
104 XSetWMProtocols(display, w->wid, &delatom, 1);
105 fixed(w, 0);
107 return p;