libxputty 0.1
Loading...
Searching...
No Matches
xcolor.c
Go to the documentation of this file.
1/*
2 * 0BSD
3 *
4 * BSD Zero Clause License
5 *
6 * Copyright (c) 2019 Hermann Meyer
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted.
10
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 *
19 */
20
21#include "xcolor.h"
22
23
25 main->color_scheme->normal = (Colors) {
26 /* cairo / r / g / b / a / */
27 .fg = { 0.85, 0.85, 0.85, 1.0},
28 .bg = { 0.1, 0.1, 0.1, 1.0},
29 .base = { 0.0, 0.0, 0.0, 1.0},
30 .text = { 0.9, 0.9, 0.9, 1.0},
31 .shadow = { 0.0, 0.0, 0.0, 0.2},
32 .frame = { 0.0, 0.0, 0.0, 1.0},
33 .light = { 0.1, 0.1, 0.1, 1.0}
34 };
35
36 main->color_scheme->prelight = (Colors) {
37 .fg = { 1.0, 0.0, 1.0, 1.0},
38 .bg = { 0.25, 0.25, 0.25, 1.0},
39 .base = { 0.3, 0.3, 0.3, 1.0},
40 .text = { 1.0, 1.0, 1.0, 1.0},
41 .shadow = { 0.1, 0.1, 0.1, 0.4},
42 .frame = { 0.3, 0.3, 0.3, 1.0},
43 .light = { 0.3, 0.3, 0.3, 1.0}
44 };
45
46 main->color_scheme->selected = (Colors) {
47 .fg = { 0.9, 0.9, 0.9, 1.0},
48 .bg = { 0.2, 0.2, 0.2, 1.0},
49 .base = { 0.5, 0.18, 0.18, 1.0},
50 .text = { 1.0, 1.0, 1.0, 1.0},
51 .shadow = { 0.8, 0.18, 0.18, 0.2},
52 .frame = { 0.5, 0.18, 0.18, 1.0},
53 .light = { 0.5, 0.18, 0.18, 1.0}
54 };
55
56 main->color_scheme->active = (Colors) {
57 .fg = { 0.0, 1.0, 1.0, 1.0},
58 .bg = { 0.0, 0.0, 0.0, 1.0},
59 .base = { 0.18, 0.38, 0.38, 1.0},
60 .text = { 0.75, 0.75, 0.75, 1.0},
61 .shadow = { 0.18, 0.38, 0.38, 0.5},
62 .frame = { 0.18, 0.38, 0.38, 1.0},
63 .light = { 0.18, 0.38, 0.38, 1.0}
64 };
65
67 .fg = { 0.85, 0.85, 0.85, 0.5},
68 .bg = { 0.1, 0.1, 0.1, 0.5},
69 .base = { 0.0, 0.0, 0.0, 0.5},
70 .text = { 0.9, 0.9, 0.9, 0.5},
71 .shadow = { 0.0, 0.0, 0.0, 0.1},
72 .frame = { 0.0, 0.0, 0.0, 0.5},
73 .light = { 0.1, 0.1, 0.1, 0.5}
74 };
75}
76
78 main->color_scheme->normal = (Colors) {
79 /* cairo / r / g / b / a / */
80 .fg = { 0.15, 0.15, 0.15, 1.0},
81 .bg = { 0.85, 0.85, 0.85, 1.0},
82 .base = { 0.9, 0.9, 0.9, 1.0},
83 .text = { 0.25, 0.25, 0.25, 1.0},
84 .shadow = { 0.0, 0.0, 0.0, 0.2},
85 .frame = { 0.2, 0.2, 0.2, 1.0},
86 .light = { 0.9, 0.9, 0.9, 1.0}
87 };
88
89 main->color_scheme->prelight = (Colors) {
90 .fg = { 0.25, 0.25, 0.25, 1.0},
91 .bg = { 1.0, 1.0, 1.0, 1.0},
92 .base = { 0.75, 0.75, 0.75, 1.0},
93 .text = { 0.15, 0.15, 0.15, 1.0},
94 .shadow = { 0.1, 0.1, 0.1, 0.4},
95 .frame = { 0.3, 0.3, 0.3, 1.0},
96 .light = { 0.75, 0.75, 0.75, 1.0}
97 };
98
99 main->color_scheme->selected = (Colors) {
100 .fg = { 0.2, 0.2, 0.2, 1.0},
101 .bg = { 0.9, 0.9, 0.9, 1.0},
102 .base = { 0.0, 0.5, 0.65, 1.0},
103 .text = { 0.8, 0.8, 0.8, 1.0},
104 .shadow = { 0.8, 0.18, 0.18, 0.2},
105 .frame = { 0.5, 0.18, 0.18, 1.0},
106 .light = { 0.5, 0.5, 0.5, 1.0}
107 };
108
109 main->color_scheme->active = (Colors) {
110 .fg = { 0.0, 0.0, 0.0, 1.0},
111 .bg = { 1.0, 1.0, 1.0, 1.0},
112 .base = { 0.0, 0.3, 0.65, 1.0},
113 .text = { 0.8, 0.8, 0.8, 1.0},
114 .shadow = { 0.18, 0.38, 0.38, 0.5},
115 .frame = { 0.18, 0.38, 0.38, 1.0},
116 .light = { 0.3, 0.3, 0.3, 1.0}
117 };
118
119 main->color_scheme->insensitive = (Colors) {
120 .fg = { 0.15, 0.15, 0.15, 0.5},
121 .bg = { 0.85, 0.85, 0.85, 0.5},
122 .base = { 0.9, 0.9, 0.9, 0.5},
123 .text = { 0.25, 0.25, 0.25, 0.5},
124 .shadow = { 0.0, 0.0, 0.0, 0.1},
125 .frame = { 0.2, 0.2, 0.2, 0.5},
126 .light = { 0.9, 0.9, 0.9, 0.5}
127 };
128}
129
131 int i=0;
132 for(;i<wid->childlist->elem;i++) {
133 Widget_t* w = wid->childlist->childs[i];
134 memcpy(w->color_scheme, wid->color_scheme, sizeof (struct XColor_t));
136 }
137}
138
139void widget_set_color(double *c, double r, double g, double b, double a) {
140 c[0] = r;
141 c[1] = g;
142 c[2] = b;
143 c[3] = a;
144}
145
147 double r, double g, double b, double a) {
148 Colors *c = get_color_scheme(w, st);
149 switch(mod) {
150 case FORGROUND_:
151 c->fg[0] = r;
152 c->fg[1] = g;
153 c->fg[2] = b;
154 c->fg[3] = a;
155 break;
156 case BACKGROUND_:
157 c->bg[0] = r;
158 c->bg[1] = g;
159 c->bg[2] = b;
160 c->bg[3] = a;
161 break;
162 case BASE_:
163 c->base[0] = r;
164 c->base[1] = g;
165 c->base[2] = b;
166 c->base[3] = a;
167 break;
168 case TEXT_:
169 c->text[0] = r;
170 c->text[1] = g;
171 c->text[2] = b;
172 c->text[3] = a;
173 break;
174 case SHADOW_:
175 c->shadow[0] = r;
176 c->shadow[1] = g;
177 c->shadow[2] = b;
178 c->shadow[3] = a;
179 break;
180 case FRAME_:
181 c->frame[0] = r;
182 c->frame[1] = g;
183 c->frame[2] = b;
184 c->frame[3] = a;
185 break;
186 case LIGHT_:
187 c->light[0] = r;
188 c->light[1] = g;
189 c->light[2] = b;
190 c->light[3] = a;
191 break;
192 default:
193 break;
194 }
195}
196
198 switch(st) {
199 case NORMAL_:
200 return &wid->color_scheme->normal;
201 break;
202 case PRELIGHT_:
203 return &wid->color_scheme->prelight;
204 break;
205 case SELECTED_:
206 return &wid->color_scheme->selected;
207 break;
208 case ACTIVE_:
209 return &wid->color_scheme->active;
210 break;
211 case INSENSITIVE_:
212 return &wid->color_scheme->insensitive;
213 break;
214 default:
215 return &wid->color_scheme->normal;
216 break;
217 }
218 return NULL;
219
220}
221
223 switch(wid->state) {
224 case 0:
225 return NORMAL_;
226 break;
227 case 1:
228 return PRELIGHT_;
229 break;
230 case 2:
231 return SELECTED_;
232 break;
233 case 3:
234 return ACTIVE_;
235 break;
236 case 4:
237 return INSENSITIVE_;
238 break;
239 default:
240 return NORMAL_;
241 break;
242 }
243}
244
246 Colors *c = get_color_scheme(w, st);
247 if (!c) return;
248 cairo_set_source_rgba(w->cr, c->fg[0], c->fg[1], c->fg[2], c->fg[3]);
249 cairo_set_source_rgba(w->crb, c->fg[0], c->fg[1], c->fg[2], c->fg[3]);
250}
251
253 Colors *c = get_color_scheme(w, st);
254 if (!c) return;
255 cairo_set_source_rgba(w->cr, c->bg[0], c->bg[1], c->bg[2], c->bg[3]);
256 cairo_set_source_rgba(w->crb, c->bg[0], c->bg[1], c->bg[2], c->bg[3]);
257}
258
260 Colors *c = get_color_scheme(w, st);
261 if (!c) return;
262 cairo_set_source_rgba(w->cr, c->base[0], c->base[1], c->base[2], c->base[3]);
263 cairo_set_source_rgba(w->crb, c->base[0], c->base[1], c->base[2], c->base[3]);
264}
265
267 Colors *c = get_color_scheme(w, st);
268 if (!c) return;
269 cairo_set_source_rgba(w->cr, c->text[0], c->text[1], c->text[2], c->text[3]);
270 cairo_set_source_rgba(w->crb, c->text[0], c->text[1], c->text[2], c->text[3]);
271}
272
274 Colors *c = get_color_scheme(w, st);
275 if (!c) return;
276 cairo_set_source_rgba(w->cr, c->shadow[0], c->shadow[1], c->shadow[2], c->shadow[3]);
277 cairo_set_source_rgba(w->crb, c->shadow[0], c->shadow[1], c->shadow[2], c->shadow[3]);
278}
279
281 Colors *c = get_color_scheme(w, st);
282 if (!c) return;
283 cairo_set_source_rgba(w->cr, c->frame[0], c->frame[1], c->frame[2], c->frame[3]);
284 cairo_set_source_rgba(w->crb, c->frame[0], c->frame[1], c->frame[2], c->frame[3]);
285}
286
288 Colors *c = get_color_scheme(w, st);
289 if (!c) return;
290 cairo_set_source_rgba(w->cr, c->light[0], c->light[1], c->light[2], c->light[3]);
291 cairo_set_source_rgba(w->crb, c->light[0], c->light[1], c->light[2], c->light[3]);
292}
293
296 cairo_set_source_rgba(w->cr, c->r, c->g, c->b, c->a);
297 cairo_set_source_rgba(w->crb, c->r, c->g, c->b, c->a);
298}
299
300void set_systray_color(Xputty *main, double r, double g, double b, double a) {
301 SystrayColor_t *c = main->systray_color;
302 c->r = r;
303 c->g = g;
304 c->b = b;
305 c->a = a;
306}
307
308void set_pattern(Widget_t *w, Colors *from, Colors *to, Color_mod mod) {
309 double *col_from = NULL;
310 double *col_to = NULL;
311 switch (mod) {
312 case FORGROUND_:
313 col_from = from->fg;
314 col_to = to->fg;
315 break;
316 case BACKGROUND_:
317 col_from = from->bg;
318 col_to = to->bg;
319 break;
320 case BASE_:
321 col_from = from->base;
322 col_to = to->base;
323 break;
324 case TEXT_:
325 col_from = from->text;
326 col_to = to->text;
327 break;
328 case SHADOW_:
329 col_from = from->shadow;
330 col_to = to->shadow;
331 break;
332 case FRAME_:
333 col_from = from->frame;
334 col_to = to->frame;
335 break;
336 case LIGHT_:
337 col_from = from->light;
338 col_to = to->light;
339 break;
340 }
341 Metrics_t metrics;
342 os_get_window_metrics(w, &metrics);
343 int width = metrics.width;
344 int height = metrics.height;
345 cairo_pattern_t *pat = cairo_pattern_create_linear (0, 0, width, height);
346 cairo_pattern_add_color_stop_rgba(pat, 0.0, col_from[0], col_from[1], col_from[2], col_from[3]);
347 cairo_pattern_add_color_stop_rgba(pat, 1.0, col_to[0], col_to[1], col_to[2], col_to[3]);
348 cairo_set_source(w->crb, pat);
349 cairo_set_source(w->cr, pat);
350 cairo_pattern_destroy (pat);
351}
Widget_t ** childs
Definition xchildlist.h:51
Color_t - struct used to set cairo color for Widget_t.
Definition xcolor.h:85
double text[4]
Definition xcolor.h:89
double fg[4]
Definition xcolor.h:86
double frame[4]
Definition xcolor.h:91
double shadow[4]
Definition xcolor.h:90
double base[4]
Definition xcolor.h:88
double bg[4]
Definition xcolor.h:87
double light[4]
Definition xcolor.h:92
Metrics_t - struct to receive window size, position & visibility Pass this struct to os_get_window_...
SystrayColor - the Systray Color struct SystrayColor could be used for the backgroung color of the Sy...
Definition xcolor.h:122
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
XColor_t * color_scheme
Definition xwidget.h:467
cairo_t * crb
Definition xwidget.h:489
int state
Definition xwidget.h:511
Childlist_t * childlist
Definition xwidget.h:499
cairo_t * cr
Definition xwidget.h:485
Xputty * app
Definition xwidget.h:465
XColor_t - the Widget_t Color struct XColor_t could be used for theming you Widget_t set.
Definition xcolor.h:105
Colors normal
Definition xcolor.h:106
Colors insensitive
Definition xcolor.h:110
Colors selected
Definition xcolor.h:108
Colors active
Definition xcolor.h:109
Colors prelight
Definition xcolor.h:107
Xputty - the main struct. It should be declared before any other call to a Xputty function....
Definition xputty.h:228
SystrayColor_t * systray_color
Definition xputty.h:236
XColor_t * color_scheme
Definition xputty.h:234
void use_frame_color_scheme(Widget_t *w, Color_state st)
use_frame_color_scheme - use frame Colors to paint on Widget_t
Definition xcolor.c:280
Color_state get_color_state(Widget_t *wid)
get_color_state - get the Color_state to use in relation to the Widget_t state
Definition xcolor.c:222
void use_text_color_scheme(Widget_t *w, Color_state st)
use_text_color_scheme - use text Colors to paint on Widget_t
Definition xcolor.c:266
void use_systray_color(Widget_t *w)
use_systray_color - use systray Colors to paint on Widget_t
Definition xcolor.c:294
void color_scheme_to_childs(Widget_t *wid)
color_scheme_to_childs - copy a colorscheme to all childs light theme
Definition xcolor.c:130
void use_bg_color_scheme(Widget_t *w, Color_state st)
use_bg_color_scheme - use background Colors to paint on Widget_t
Definition xcolor.c:252
void use_fg_color_scheme(Widget_t *w, Color_state st)
use_fg_color_scheme - use forground Colors to paint on Widget_t
Definition xcolor.c:245
void set_pattern(Widget_t *w, Colors *from, Colors *to, Color_mod mod)
set_pattern - set pattern for the selected Colors
Definition xcolor.c:308
void set_light_theme(Xputty *main)
set_light_theme - init the XColor_t struct to the default light theme
Definition xcolor.c:77
void use_light_color_scheme(Widget_t *w, Color_state st)
use_light_color_scheme - use light Colors to paint on Widget_t
Definition xcolor.c:287
void set_dark_theme(Xputty *main)
set_dark_theme - init the XColor_t struct to the default dark theme
Definition xcolor.c:24
Colors * get_color_scheme(Widget_t *wid, Color_state st)
get_color_scheme - get pointer to the Colors struct to use in relation to the Color_state
Definition xcolor.c:197
void set_widget_color(Widget_t *w, Color_state st, Color_mod mod, double r, double g, double b, double a)
set_widget_color - set a individual Widget_t color
Definition xcolor.c:146
void use_shadow_color_scheme(Widget_t *w, Color_state st)
use_shadow_color_scheme - use shadow Colors to paint on Widget_t
Definition xcolor.c:273
void set_systray_color(Xputty *main, double r, double g, double b, double a)
set_systray_color - set the systray background color
Definition xcolor.c:300
void use_base_color_scheme(Widget_t *w, Color_state st)
use_base_color_scheme - use base Colors to paint on Widget_t
Definition xcolor.c:259
void widget_set_color(double *c, double r, double g, double b, double a)
widget_set_color - set a individual Widget_t color
Definition xcolor.c:139
Color_mod
Color_mod - select color mod to use on draw.
Definition xcolor.h:63
@ BASE_
Definition xcolor.h:66
@ SHADOW_
Definition xcolor.h:68
@ FRAME_
Definition xcolor.h:69
@ FORGROUND_
Definition xcolor.h:64
@ BACKGROUND_
Definition xcolor.h:65
@ TEXT_
Definition xcolor.h:67
@ LIGHT_
Definition xcolor.h:70
Color_state
Color_state - select color mode to use on Widget_t.
Definition xcolor.h:43
@ NORMAL_
Definition xcolor.h:44
@ INSENSITIVE_
Definition xcolor.h:48
@ SELECTED_
Definition xcolor.h:46
@ PRELIGHT_
Definition xcolor.h:45
@ ACTIVE_
Definition xcolor.h:47
void os_get_window_metrics(Widget_t *w, Metrics_t *metrics)
os_get_window_metrics - Get the Merics_t struct related to a Widget_t