-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSection.cpp
More file actions
185 lines (147 loc) · 4.7 KB
/
Section.cpp
File metadata and controls
185 lines (147 loc) · 4.7 KB
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
180
181
182
183
184
185
/*
* Copyright (c) 2010 Andry Gunawan <angun33@gmail.com>
*
* Parts of this file are based on Telescope which is
* Copyright (c) 2010 Ilya Skriblovsky <Ilya.Skriblovsky@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <libintl.h>
#include <locale.h>
#include "Section.h"
#include "constant.h"
#include "XTools.h"
#include "Image.h"
XftFont *Section::_xftFont = 0;
Section::Section(Display *dpy, const gchar *name)
:_dpy(dpy), _icon(0), _iconOwned(false), _iconChangedCallback(0)
{
setName(name);
_partNo = 1;
_applications = g_ptr_array_new();
}
Section::~Section()
{
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Section dtor");
for (guint i = 0; i < _applications->len; i++)
{
delete getApplication(i);
}
g_ptr_array_free(_applications, TRUE);
g_free(_name);
if ( _xftFont != 0 )
{
XftFontClose( _dpy, _xftFont );
_xftFont = 0;
}
if (_iconOwned)
delete _icon;
}
void Section::setPart(guint partNo)
{
_partNo = partNo;
}
guint Section::getPart()
{
return _partNo;
}
void Section::setName(const gchar *name)
{
_name = g_strdup(name);
// char* upcase = g_utf8_strup(name, -1);
//
// if (upcase && strstr(upcase, "UTIL")) _icon = new Image(_dpy, "/home/user/telescope/panel-icons/games.png");
// if (upcase && strstr(upcase, "COMMU")) _icon = new Image(_dpy, "/home/user/telescope/panel-icons/comm.png");
// if (upcase && strstr(upcase, "EXTRA")) _icon = new Image(_dpy, "/home/user/telescope/panel-icons/extras.png");
// if (upcase && strstr(upcase, "INTERN")) _icon = new Image(_dpy, "/home/user/telescope/panel-icons/web.png");
// if (upcase && strstr(upcase, "SETTI")) _icon = new Image(_dpy, "/home/user/telescope/panel-icons/settings.png");
//
// g_free(upcase);
}
const gchar * Section::getName()
{
return _name;
}
void Section::setIcon(Image *icon, bool own)
{
printf("setIcon(%p, %d)\n", icon, own);
if (_iconOwned)
delete _icon;
_icon = icon;
_iconOwned = own;
if (_iconChangedCallback)
_iconChangedCallback(this, _iconChangedCallbackData);
}
gchar * Section::getNameWithPart()
{
if (_partNo != 1)
return g_strdup_printf("%s — part %u", gettext( _name ), _partNo);
else
return g_strdup( gettext( _name ) );
}
Application * Section::getApplication(guint index)
{
return (Application *) g_ptr_array_index(_applications, index);
}
void Section::addApplication(Application *app)
{
g_ptr_array_add(_applications, (gpointer) app);
}
guint Section::getApplicationsSize()
{
return _applications->len;
}
void Section::draw(Display *dpy, Image* image, int x, int y, int width, int height )
{
// position the applications and draw them
uint col, row;
col = row = 0;
Application * app;
bool landscape = width >= height;
uint cols = landscape ? NUM_COLS : NUM_ROWS; // (width - 2 * xborder + xmingap) / (Application::width() + xmingap);
uint rows = landscape ? NUM_ROWS : NUM_COLS;
//int xgap = (width - 2 * xborder - Application::width() * cols) / (cols - 1);
int xgap = (width / cols - Application::width()) / 2;
//int ygap = 36;
int ygap = (height / rows - Application::height()) / 2;
for ( uint i = 0; i < _applications->len; i++ )
{
if ( col >= cols )
{
col = 0;
row++;
}
// if ( row >= NUM_ROWS )
// break;
// draw the app icon
app = getApplication ( i );
app->setPosition(
x + col * width / cols + xgap,
y + row * height / rows + ygap
);
// blit the icon into the section pixmap
XRenderComposite ( _dpy, PictOpOver,
app->image()->picture(), None, image->picture(),
0, 0,
0, 0,
app->x(), app->y(),
app->width(), app->height());
col++;
}
}
void Section::setIconChangedCallback(IconChangedCallback callback, void *data)
{
_iconChangedCallback = callback;
_iconChangedCallbackData = data;
}