summaryrefslogtreecommitdiff
path: root/src/Config.cpp
blob: abc1b70b20badd7004cd5b4d11492d204143f1c0 (plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* $Id: Config.cpp,v 1.15 2006/10/25 08:04:52 whot Exp $ */

/*--
  --*/

#include "Config.h"

Config* Config::instance = NULL;

/**
 * @return The instance of the configuration.
 * @throws ConfigurationError if the config was not initialized before.
 * @see Config::init
 */
Config* Config::getInstance()
{
    if (instance == NULL)
        throw new ConfigurationError();

    return instance;
}


/**
 * Call this method to initialize the WM config. Otherwise getInstance() will
 * throw an error.
 * @param dpy The X11 display.
 * @param root X11 root window.
 * @param screen The used screen.
 */
void Config::init(XConn* x11)
{
    Config::instance = new Config(x11);
}


/**
 * This is a protected constructor. Do not call it. There can only be one
 * configuration per window manager.
 * Eventually this will load data from a file.
 * @param dpy The X11 display.
 * @param root X11 root window.
 * @param screen The used screen.
 */
Config::Config(XConn* x11)
{

    this->x11 = x11;
    clientOffset = 3;
    imgBackground = IMAGEPATH "background.png";
    kbdImage = IMAGEPATH "keyboard.png";
    windowBarHeight = 30;

    buttonWidth = 20;
    buttonHeight = 10;

    resizeBarHeight = 20;

    resizeButtonHeight = resizeBarHeight;
    resizeButtonWidth = 20;

    buttonCloseX = 50;
    buttonCloseY= 10;

    buttonMinimizeX = buttonCloseX + 30;
    buttonMinimizeY = buttonCloseY;

    buttonFloorX = buttonMinimizeX + 30;
    buttonFloorY = buttonCloseY;

    buttonOverlayX = buttonFloorX + 30;
    buttonOverlayY = buttonFloorY;

    buttonOwnerX = buttonOverlayX + 30;
    buttonOwnerY = buttonFloorY;

    // pencil sizes for overlay
    drawLineWidth = 4;
    eraseLineWidth = 25;

    /*
       The applications for the dock.
     */
    apps.push_back(new DockApp(x11, "firefox &", IMAGEPATH "firefox.png"));
    apps.push_back(new DockApp(x11, "gnome-terminal &", IMAGEPATH "terminal.png"));
    apps.push_back(new DockApp(x11, "gnome-calculator &", IMAGEPATH "calculator.png"));
    apps.push_back(new DockApp(x11, "abiword &", IMAGEPATH "abiword.png"));
    apps.push_back(new DockApp(x11, "gimp --no-splash &", IMAGEPATH "gimp.png"));
    apps.push_back(new DockApp(x11, "malaminya &", IMAGEPATH "malaminya.png"));
}


static void HSVtoRGB( float *r, float *g, float *b, float h, float s, float v );
long Config::cursorColor(int id)
{
    float r, g, b;


    HSVtoRGB(&r, &g, &b, (85 * id) % 360, 1, 1);

    XColor color;
    color.red = (int)(65535 * r);
    color.blue = (int)(65535 * g);
    color.green = (int)(65535 * b);


    TRACE("allocating %d/%d/%d for pointer %d\n", color.red, color.green, color.blue, id);
    
    long pixel = XAllocColor(x11->dpy, x11->cmap, &color);

    TRACE(" - result %d/%d/%d (pixel %ld)\n", color.red, color.green, color.blue, color.pixel);

    if (!pixel)
    {
        ERR(" -cannot allocate color\n");
        pixel = x11->white;
    }

    return color.pixel;

}


/* Taken from http://www.cs.rit.edu/~ncs/color/t_convert.html */
static void HSVtoRGB( float *r, float *g, float *b, 
        float h, float s, float v )
{
    int i;
    float f, p, q, t;

    if( s == 0 ) {
        // achromatic (grey)
        *r = *g = *b = v;
        return;
    }

    h /= 60;// sector 0 to 5
    i = (h >= 0) ? (int)h : (int)(h - 1);
    f = h - i;// factorial part of h
    p = v * ( 1 - s );
    q = v * ( 1 - s * f );
    t = v * ( 1 - s * ( 1 - f ) );

    switch( i ) {
        case 0:
            *r = v;
            *g = t;
            *b = p;
            break;
        case 1:
            *r = q;
            *g = v;
            *b = p;
            break;
        case 2:
            *r = p;
            *g = v;
            *b = t;
            break;
        case 3:
            *r = p;
            *g = q;
            *b = v;
            break;
        case 4:
            *r = t;
            *g = p;
            *b = v;
            break;
        default:// case 5:
            *r = v;
            *g = p;
            *b = q;
            break;
    }

}