libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xcolor.h File Reference
#include "xputty.h"
Include dependency graph for xcolor.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Colors
 Color_t - struct used to set cairo color for Widget_t. More...
 
struct  XColor_t
 XColor_t - the Widget_t Color struct
XColor_t could be used for theming you Widget_t set. More...
 

Macros

#define XCOLOR_H_
 

Enumerations

enum  Color_state {
  NORMAL_, PRELIGHT_, SELECTED_, ACTIVE_,
  INSENSITIVE_
}
 Color_state - select color mode to use on Widget_t. More...
 
enum  Color_mod {
  FORGROUND_, BACKGROUND_, BASE_, TEXT_,
  SHADOW_, FRAME_, LIGHT_
}
 Color_set - select color set to use on draw. More...
 

Functions

void set_dark_theme (Xputty *main)
 set_dark_theme - init the XColor_t struct to the default dark theme More...
 
void set_light_theme (Xputty *main)
 set_light_theme - init the XColor_t struct to the default light theme More...
 
Colorsget_color_scheme (Xputty *main, Color_state st)
 get_color_scheme - get pointer to the Colors struct to use in relation to the Color_state More...
 
Color_state get_color_state (Widget_t *wid)
 get_color_state - get the Color_state to use in relation to the Widget_t state More...
 
void use_fg_color_scheme (Widget_t *w, Color_state st)
 use_fg_color_scheme - use forground Colors to paint on Widget_t More...
 
void use_bg_color_scheme (Widget_t *w, Color_state st)
 use_bg_color_scheme - use background Colors to paint on Widget_t More...
 
void use_base_color_scheme (Widget_t *w, Color_state st)
 use_base_color_scheme - use base Colors to paint on Widget_t More...
 
void use_text_color_scheme (Widget_t *w, Color_state st)
 use_text_color_scheme - use text Colors to paint on Widget_t More...
 
void use_shadow_color_scheme (Widget_t *w, Color_state st)
 use_shadow_color_scheme - use shadow Colors to paint on Widget_t More...
 
void use_frame_color_scheme (Widget_t *w, Color_state st)
 use_frame_color_scheme - use frame Colors to paint on Widget_t More...
 
void use_light_color_scheme (Widget_t *w, Color_state st)
 use_light_color_scheme - use light Colors to paint on Widget_t More...
 
void set_pattern (Widget_t *w, Colors *from, Colors *to, Color_mod mod)
 set_pattern - set pattern for the selected Colors More...
 

Macro Definition Documentation

◆ XCOLOR_H_

#define XCOLOR_H_

Definition at line 24 of file xcolor.h.

Enumeration Type Documentation

◆ Color_mod

enum Color_mod

Color_set - select color set to use on draw.

Enumerator
FORGROUND_ 
BACKGROUND_ 
BASE_ 
TEXT_ 
SHADOW_ 
FRAME_ 
LIGHT_ 

Definition at line 51 of file xcolor.h.

51  {
52  FORGROUND_,
54  BASE_,
55  TEXT_,
56  SHADOW_,
57  FRAME_,
58  LIGHT_,
59 } Color_mod;

◆ Color_state

Color_state - select color mode to use on Widget_t.

Enumerator
NORMAL_ 
PRELIGHT_ 
SELECTED_ 
ACTIVE_ 
INSENSITIVE_ 

Definition at line 38 of file xcolor.h.

38  {
39  NORMAL_,
40  PRELIGHT_,
41  SELECTED_,
42  ACTIVE_,
44 } Color_state;

Function Documentation

◆ get_color_scheme()

Colors* get_color_scheme ( Xputty main,
Color_state  st 
)

get_color_scheme - get pointer to the Colors struct to use in relation to the Color_state

Parameters
*st- the Color state to use
Returns
void

Definition at line 130 of file xcolor.c.

130  {
131  switch(st) {
132  case NORMAL_:
133  return &main->color_scheme->normal;
134  break;
135  case PRELIGHT_:
136  return &main->color_scheme->prelight;
137  break;
138  case SELECTED_:
139  return &main->color_scheme->selected;
140  break;
141  case ACTIVE_:
142  return &main->color_scheme->active;
143  break;
144  case INSENSITIVE_:
145  return &main->color_scheme->insensitive;
146  break;
147  default:
148  return &main->color_scheme->normal;
149  break;
150  }
151  return NULL;
152 
153 }

References XColor_t::active, ACTIVE_, Xputty::color_scheme, XColor_t::insensitive, INSENSITIVE_, XColor_t::normal, NORMAL_, XColor_t::prelight, PRELIGHT_, XColor_t::selected, and SELECTED_.

◆ get_color_state()

Color_state get_color_state ( Widget_t wid)

get_color_state - get the Color_state to use in relation to the Widget_t state

Parameters
*wid- pointer to the Widget_t
Returns
Color_state - the Color_state related to the Widget_t state

Definition at line 155 of file xcolor.c.

155  {
156  switch(wid->state) {
157  case 0:
158  return NORMAL_;
159  break;
160  case 1:
161  return PRELIGHT_;
162  break;
163  case 2:
164  return SELECTED_;
165  break;
166  case 3:
167  return ACTIVE_;
168  break;
169  case 4:
170  return INSENSITIVE_;
171  break;
172  default:
173  return NORMAL_;
174  break;
175  }
176 }

References ACTIVE_, INSENSITIVE_, NORMAL_, PRELIGHT_, SELECTED_, and Widget_t::state.

◆ set_dark_theme()

void set_dark_theme ( Xputty main)

set_dark_theme - init the XColor_t struct to the default dark theme

Parameters
*main- pointer to the main Xputty struct
Returns
void

Definition at line 24 of file xcolor.c.

24  {
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 
66  main->color_scheme->insensitive = (Colors) {
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 }

References XColor_t::active, Xputty::color_scheme, Colors::fg, XColor_t::insensitive, XColor_t::normal, XColor_t::prelight, and XColor_t::selected.

◆ set_light_theme()

void set_light_theme ( Xputty main)

set_light_theme - init the XColor_t struct to the default light theme

Parameters
*main- pointer to the main Xputty struct
Returns
void

Definition at line 77 of file xcolor.c.

77  {
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 }

References XColor_t::active, Xputty::color_scheme, Colors::fg, XColor_t::insensitive, XColor_t::normal, XColor_t::prelight, and XColor_t::selected.

◆ set_pattern()

void set_pattern ( Widget_t w,
Colors from,
Colors to,
Color_mod  mod 
)

set_pattern - set pattern for the selected Colors

Parameters
*w_- pointer to the Widget_t to set the pattern
*from- the Colors set to pattern from (0)
*to- the Colors set to pattern to (1)
mod- the Color_mod to use
Returns
void

Definition at line 227 of file xcolor.c.

227  {
228  double *col_from = NULL;
229  double *col_to = NULL;
230  switch (mod) {
231  case FORGROUND_:
232  col_from = from->fg;
233  col_to = to->fg;
234  break;
235  case BACKGROUND_:
236  col_from = from->bg;
237  col_to = to->bg;
238  break;
239  case BASE_:
240  col_from = from->base;
241  col_to = to->base;
242  break;
243  case TEXT_:
244  col_from = from->text;
245  col_to = to->text;
246  break;
247  case SHADOW_:
248  col_from = from->shadow;
249  col_to = to->shadow;
250  break;
251  case FRAME_:
252  col_from = from->frame;
253  col_to = to->frame;
254  break;
255  case LIGHT_:
256  col_from = from->light;
257  col_to = to->light;
258  break;
259  }
260  XWindowAttributes attrs;
261  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
262  int width = attrs.width;
263  int height = attrs.height;
264  cairo_pattern_t *pat = cairo_pattern_create_linear (0, 0, width, height);
265  cairo_pattern_add_color_stop_rgba(pat, 0.0, col_from[0], col_from[1], col_from[2], col_from[3]);
266  cairo_pattern_add_color_stop_rgba(pat, 1.0, col_to[0], col_to[1], col_to[2], col_to[3]);
267  cairo_set_source(w->crb, pat);
268  cairo_set_source(w->cr, pat);
269  cairo_pattern_destroy (pat);
270 }

References Widget_t::app, BACKGROUND_, Colors::base, BASE_, Colors::bg, Widget_t::cr, Widget_t::crb, Xputty::dpy, Colors::fg, FORGROUND_, Colors::frame, FRAME_, Colors::light, LIGHT_, Colors::shadow, SHADOW_, Colors::text, TEXT_, and Widget_t::widget.

◆ use_base_color_scheme()

void use_base_color_scheme ( Widget_t w,
Color_state  st 
)

use_base_color_scheme - use base Colors to paint on Widget_t

Parameters
w- the Widget_t to set the Colors
st- the Color_state to use
Returns
void

Definition at line 192 of file xcolor.c.

192  {
193  Colors *c = get_color_scheme(w->app, st);
194  if (!c) return;
195  cairo_set_source_rgba(w->cr, c->base[0], c->base[1], c->base[2], c->base[3]);
196  cairo_set_source_rgba(w->crb, c->base[0], c->base[1], c->base[2], c->base[3]);
197 }

References Widget_t::app, Colors::base, Widget_t::cr, Widget_t::crb, and get_color_scheme().

◆ use_bg_color_scheme()

void use_bg_color_scheme ( Widget_t w,
Color_state  st 
)

use_bg_color_scheme - use background Colors to paint on Widget_t

Parameters
w- the Widget_t to set the Colors
st- the Color_state to use
Returns
void

Definition at line 185 of file xcolor.c.

185  {
186  Colors *c = get_color_scheme(w->app, st);
187  if (!c) return;
188  cairo_set_source_rgba(w->cr, c->bg[0], c->bg[1], c->bg[2], c->bg[3]);
189  cairo_set_source_rgba(w->crb, c->bg[0], c->bg[1], c->bg[2], c->bg[3]);
190 }

References Widget_t::app, Colors::bg, Widget_t::cr, Widget_t::crb, and get_color_scheme().

◆ use_fg_color_scheme()

void use_fg_color_scheme ( Widget_t w,
Color_state  st 
)

use_fg_color_scheme - use forground Colors to paint on Widget_t

Parameters
*w- the Widget_t to set the Colors
st- the Color_state to use
Returns
void

Definition at line 178 of file xcolor.c.

178  {
179  Colors *c = get_color_scheme(w->app, st);
180  if (!c) return;
181  cairo_set_source_rgba(w->cr, c->fg[0], c->fg[1], c->fg[2], c->fg[3]);
182  cairo_set_source_rgba(w->crb, c->fg[0], c->fg[1], c->fg[2], c->fg[3]);
183 }

References Widget_t::app, Widget_t::cr, Widget_t::crb, Colors::fg, and get_color_scheme().

◆ use_frame_color_scheme()

void use_frame_color_scheme ( Widget_t w,
Color_state  st 
)

use_frame_color_scheme - use frame Colors to paint on Widget_t

Parameters
w- the Widget_t to set the Colors
st- the Color_state to use
Returns
void

Definition at line 213 of file xcolor.c.

213  {
214  Colors *c = get_color_scheme(w->app, st);
215  if (!c) return;
216  cairo_set_source_rgba(w->cr, c->frame[0], c->frame[1], c->frame[2], c->frame[3]);
217  cairo_set_source_rgba(w->crb, c->frame[0], c->frame[1], c->frame[2], c->frame[3]);
218 }

References Widget_t::app, Widget_t::cr, Widget_t::crb, Colors::frame, and get_color_scheme().

◆ use_light_color_scheme()

void use_light_color_scheme ( Widget_t w,
Color_state  st 
)

use_light_color_scheme - use light Colors to paint on Widget_t

Parameters
w- the Widget_t to set the Colors
st- the Color_state to use
Returns
void

Definition at line 220 of file xcolor.c.

220  {
221  Colors *c = get_color_scheme(w->app, st);
222  if (!c) return;
223  cairo_set_source_rgba(w->cr, c->light[0], c->light[1], c->light[2], c->light[3]);
224  cairo_set_source_rgba(w->crb, c->light[0], c->light[1], c->light[2], c->light[3]);
225 }

References Widget_t::app, Widget_t::cr, Widget_t::crb, get_color_scheme(), and Colors::light.

◆ use_shadow_color_scheme()

void use_shadow_color_scheme ( Widget_t w,
Color_state  st 
)

use_shadow_color_scheme - use shadow Colors to paint on Widget_t

Parameters
w- the Widget_t to set the Colors
st- the Color_state to use
Returns
void

Definition at line 206 of file xcolor.c.

206  {
207  Colors *c = get_color_scheme(w->app, st);
208  if (!c) return;
209  cairo_set_source_rgba(w->cr, c->shadow[0], c->shadow[1], c->shadow[2], c->shadow[3]);
210  cairo_set_source_rgba(w->crb, c->shadow[0], c->shadow[1], c->shadow[2], c->shadow[3]);
211 }

References Widget_t::app, Widget_t::cr, Widget_t::crb, get_color_scheme(), and Colors::shadow.

◆ use_text_color_scheme()

void use_text_color_scheme ( Widget_t w,
Color_state  st 
)

use_text_color_scheme - use text Colors to paint on Widget_t

Parameters
w- the Widget_t to set the Colors
st- the Color_state to use
Returns
void

Definition at line 199 of file xcolor.c.

199  {
200  Colors *c = get_color_scheme(w->app, st);
201  if (!c) return;
202  cairo_set_source_rgba(w->cr, c->text[0], c->text[1], c->text[2], c->text[3]);
203  cairo_set_source_rgba(w->crb, c->text[0], c->text[1], c->text[2], c->text[3]);
204 }

References Widget_t::app, Widget_t::cr, Widget_t::crb, get_color_scheme(), and Colors::text.

XColor_t::active
Colors active
Definition: xcolor.h:92
Colors::text
double text[4]
Definition: xcolor.h:77
FRAME_
@ FRAME_
Definition: xcolor.h:57
Colors::bg
double bg[4]
Definition: xcolor.h:75
SHADOW_
@ SHADOW_
Definition: xcolor.h:56
INSENSITIVE_
@ INSENSITIVE_
Definition: xcolor.h:43
Colors::base
double base[4]
Definition: xcolor.h:76
BASE_
@ BASE_
Definition: xcolor.h:54
FORGROUND_
@ FORGROUND_
Definition: xcolor.h:52
XColor_t::insensitive
Colors insensitive
Definition: xcolor.h:93
Widget_t::crb
cairo_t * crb
Definition: xwidget.h:318
Widget_t::cr
cairo_t * cr
Definition: xwidget.h:314
BACKGROUND_
@ BACKGROUND_
Definition: xcolor.h:53
TEXT_
@ TEXT_
Definition: xcolor.h:55
XColor_t::prelight
Colors prelight
Definition: xcolor.h:90
LIGHT_
@ LIGHT_
Definition: xcolor.h:58
Widget_t::app
Xputty * app
Definition: xwidget.h:300
Xputty::dpy
Display * dpy
Definition: xputty.h:181
Widget_t::state
int state
Definition: xwidget.h:342
Colors
Color_t - struct used to set cairo color for Widget_t.
Definition: xcolor.h:73
ACTIVE_
@ ACTIVE_
Definition: xcolor.h:42
Widget_t::widget
Window widget
Definition: xwidget.h:302
XColor_t::selected
Colors selected
Definition: xcolor.h:91
get_color_scheme
Colors * get_color_scheme(Xputty *main, Color_state st)
get_color_scheme - get pointer to the Colors struct to use in relation to the Color_state
Definition: xcolor.c:130
NORMAL_
@ NORMAL_
Definition: xcolor.h:39
PRELIGHT_
@ PRELIGHT_
Definition: xcolor.h:40
Colors::frame
double frame[4]
Definition: xcolor.h:79
Color_mod
Color_mod
Color_set - select color set to use on draw.
Definition: xcolor.h:51
Xputty::color_scheme
XColor_t * color_scheme
Definition: xputty.h:183
SELECTED_
@ SELECTED_
Definition: xcolor.h:41
Colors::light
double light[4]
Definition: xcolor.h:80
Color_state
Color_state
Color_state - select color mode to use on Widget_t.
Definition: xcolor.h:38
XColor_t::normal
Colors normal
Definition: xcolor.h:89
Colors::shadow
double shadow[4]
Definition: xcolor.h:78
Colors::fg
double fg[4]
Definition: xcolor.h:74