c178e9e9988358a05555217852cd9dee0e58d891
[mikachu/openbox.git] / obrender / button.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    button.c for the Openbox window manager
4    Copyright (c) 2012        Mikael Magnusson
5    Copyright (c) 2012        Dana Jansens
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "render.h"
21 #include "instance.h"
22 #include "mask.h"
23
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #include <string.h>
27
28 RrButton *RrButtonNew (const RrInstance *inst)
29 {
30     RrButton *out = NULL;
31
32     out = g_new(RrButton, 1);
33     out->inst = inst;
34
35     /* no need to alloc colors, set them null (for freeing later) */
36     out->focused_unpressed_color = NULL;
37     out->unfocused_unpressed_color = NULL;
38     out->focused_pressed_color = NULL;
39     out->unfocused_pressed_color = NULL;
40     out->focused_disabled_color = NULL;
41     out->unfocused_disabled_color = NULL;
42     out->focused_hover_color = NULL;
43     out->unfocused_hover_color = NULL;
44     out->focused_hover_toggled_color = NULL;
45     out->unfocused_hover_toggled_color = NULL;
46     out->focused_pressed_toggled_color = NULL;
47     out->unfocused_pressed_toggled_color = NULL;
48     out->focused_unpressed_toggled_color = NULL;
49     out->unfocused_unpressed_toggled_color = NULL;
50
51     /* same with masks */
52     out->mask = NULL;
53     out->pressed_mask = NULL;
54     out->disabled_mask = NULL;
55     out->hover_mask = NULL;
56     out->toggled_mask = NULL;
57     out->hover_toggled_mask = NULL;
58     out->pressed_toggled_mask = NULL;
59
60     /* allocate appearances */
61     out->a_focused_unpressed = RrAppearanceNew(inst, 1);
62     out->a_unfocused_unpressed = RrAppearanceNew(inst, 1);
63     out->a_focused_pressed = RrAppearanceNew(inst, 1);
64     out->a_unfocused_pressed = RrAppearanceNew(inst, 1);
65     out->a_focused_disabled = RrAppearanceNew(inst, 1);
66     out->a_unfocused_disabled = RrAppearanceNew(inst, 1);
67     out->a_focused_hover = RrAppearanceNew(inst, 1);
68     out->a_unfocused_hover = RrAppearanceNew(inst, 1);
69     out->a_focused_unpressed_toggled = RrAppearanceNew(inst, 1);
70     out->a_unfocused_unpressed_toggled = RrAppearanceNew(inst, 1);
71     out->a_focused_pressed_toggled = RrAppearanceNew(inst, 1);
72     out->a_unfocused_pressed_toggled = RrAppearanceNew(inst, 1);
73     out->a_focused_hover_toggled = RrAppearanceNew(inst, 1);
74     out->a_unfocused_hover_toggled = RrAppearanceNew(inst, 1);
75
76     return out;
77 }
78
79 void RrButtonFree(RrButton *b)
80 {
81     /* colors */
82     if (b->focused_unpressed_color) 
83         RrColorFree(b->focused_unpressed_color);
84     if (b->unfocused_unpressed_color) 
85         RrColorFree(b->unfocused_unpressed_color);
86     if (b->focused_pressed_color) 
87         RrColorFree(b->focused_pressed_color);
88     if (b->unfocused_pressed_color) 
89         RrColorFree(b->unfocused_pressed_color);
90     if (b->focused_disabled_color) 
91         RrColorFree(b->focused_disabled_color);
92     if (b->unfocused_disabled_color) 
93         RrColorFree(b->unfocused_disabled_color);
94     if (b->focused_hover_color) 
95         RrColorFree(b->focused_hover_color);
96     if (b->unfocused_hover_color) 
97         RrColorFree(b->unfocused_hover_color);
98     if (b->focused_hover_toggled_color) 
99         RrColorFree(b->focused_hover_toggled_color);
100     if (b->unfocused_hover_toggled_color) 
101         RrColorFree(b->unfocused_hover_toggled_color);
102     if (b->focused_pressed_toggled_color) 
103         RrColorFree(b->focused_pressed_toggled_color);
104     if (b->unfocused_pressed_toggled_color) 
105         RrColorFree(b->unfocused_pressed_toggled_color);
106     if (b->focused_unpressed_toggled_color) 
107         RrColorFree(b->focused_unpressed_toggled_color);
108     if (b->unfocused_unpressed_toggled_color) 
109         RrColorFree(b->unfocused_unpressed_toggled_color);
110
111     /* masks */
112     if (b->mask) RrPixmapMaskFree(b->mask);
113     if (b->pressed_mask) RrPixmapMaskFree(b->pressed_mask);
114     if (b->disabled_mask) RrPixmapMaskFree(b->disabled_mask);
115     if (b->hover_mask) RrPixmapMaskFree(b->hover_mask);
116     if (b->toggled_mask) RrPixmapMaskFree(b->toggled_mask);
117     if (b->hover_toggled_mask) RrPixmapMaskFree(b->hover_toggled_mask);
118     if (b->pressed_toggled_mask) RrPixmapMaskFree(b->pressed_toggled_mask);
119
120     /* appearances */
121     RrAppearanceFree(b->a_focused_unpressed);
122     RrAppearanceFree(b->a_unfocused_unpressed);
123     RrAppearanceFree(b->a_focused_pressed);
124     RrAppearanceFree(b->a_unfocused_pressed);
125     RrAppearanceFree(b->a_focused_disabled);
126     RrAppearanceFree(b->a_unfocused_disabled);
127     RrAppearanceFree(b->a_focused_hover);
128     RrAppearanceFree(b->a_unfocused_hover);
129     RrAppearanceFree(b->a_focused_unpressed_toggled);
130     RrAppearanceFree(b->a_unfocused_unpressed_toggled);
131     RrAppearanceFree(b->a_focused_pressed_toggled);
132     RrAppearanceFree(b->a_unfocused_pressed_toggled);
133     RrAppearanceFree(b->a_focused_hover_toggled);
134     RrAppearanceFree(b->a_unfocused_hover_toggled);
135 }