[go: up one dir, main page]

Menu

[e0151d]: / src / aworkspaces.cc  Maximize  Restore  History

Download this file

201 lines (166 with data), 5.3 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "config.h"
#ifdef CONFIG_TASKBAR
#include "ylib.h"
#include "aworkspaces.h"
#include "wmtaskbar.h"
#include "prefs.h"
#include "wmmgr.h"
#include "wmapp.h"
#include "wmframe.h"
#include "intl.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include "base.h"
YColor * WorkspaceButton::normalButtonBg(NULL);
YColor * WorkspaceButton::normalButtonFg(NULL);
YColor * WorkspaceButton::activeButtonBg(NULL);
YColor * WorkspaceButton::activeButtonFg(NULL);
YFont * WorkspaceButton::normalButtonFont(NULL);
YFont * WorkspaceButton::activeButtonFont(NULL);
YPixmap *workspacebuttonPixmap(NULL);
YPixmap *workspacebuttonactivePixmap(NULL);
#ifdef CONFIG_GRADIENTS
class YPixbuf *workspacebuttonPixbuf(NULL);
class YPixbuf *workspacebuttonactivePixbuf(NULL);
#endif
WorkspaceButton::WorkspaceButton(long ws, YWindow *parent): YButton(parent, 0)
{
fWorkspace = ws;
//setDND(true);
}
void WorkspaceButton::handleClick(const XButtonEvent &/*up*/, int /*count*/) {
}
void WorkspaceButton::handleDNDEnter() {
if (fRaiseTimer == 0)
fRaiseTimer = new YTimer(autoRaiseDelay);
if (fRaiseTimer) {
fRaiseTimer->setTimerListener(this);
fRaiseTimer->startTimer();
}
repaint();
}
void WorkspaceButton::handleDNDLeave() {
if (fRaiseTimer && fRaiseTimer->getTimerListener() == this) {
fRaiseTimer->stopTimer();
fRaiseTimer->setTimerListener(0);
}
repaint();
}
bool WorkspaceButton::handleTimer(YTimer *t) {
if (t == fRaiseTimer) {
manager->activateWorkspace(fWorkspace);
}
return false;
}
void WorkspaceButton::actionPerformed(YAction */*action*/, unsigned int modifiers) {
if (modifiers & ShiftMask) {
manager->switchToWorkspace(fWorkspace, true);
} else if (modifiers & app->AltMask) {
if (manager->getFocus())
manager->getFocus()->wmOccupyWorkspace(fWorkspace);
} else {
manager->activateWorkspace(fWorkspace);
return;
}
}
WorkspacesPane::WorkspacesPane(YWindow *parent): YWindow(parent) {
long w;
if (workspaceCount > 1)
fWorkspaceButton = new WorkspaceButton *[workspaceCount];
else
fWorkspaceButton = 0;
if (fWorkspaceButton) {
YResourcePaths paths("", false);
int ht = 0;
int leftX = 0;
for (w = 0; w < workspaceCount; w++) {
WorkspaceButton *wk = new WorkspaceButton(w, this);
if (wk) {
YIcon::Image * image
(paths.loadImage("workspace/", workspaceNames[w]));
if (image) wk->setImage(image);
else wk->setText(workspaceNames[w]);
char * wn(newstr(basename(workspaceNames[w])));
char * ext(strrchr(wn, '.'));
if (ext) *ext = '\0';
char * tt(strJoin(_("Workspace: "), wn, NULL));
delete[] wn;
wk->setToolTip(tt);
delete[] tt;
if ((int)wk->height() + 1 > ht) ht = wk->height() + 1;
}
fWorkspaceButton[w] = wk;
}
for (w = 0; w < workspaceCount; w++) {
YButton *wk = fWorkspaceButton[w];
//leftX += 2;
if (wk) {
wk->setSize(wk->width(), ht);
wk->setPosition(leftX, 0); // + (ht - ADD - wk->height()) / 2);
wk->show();
leftX += wk->width();
}
}
setSize(leftX, ht);
}
}
WorkspacesPane::~WorkspacesPane() {
if (fWorkspaceButton) {
for (long w = 0; w < workspaceCount; w++)
delete fWorkspaceButton[w];
delete [] fWorkspaceButton;
}
}
WorkspaceButton *WorkspacesPane::workspaceButton(long n) {
return (fWorkspaceButton ? fWorkspaceButton[n] : NULL);
}
YFont * WorkspaceButton::getFont() {
return isPressed()
? *activeWorkspaceFontName
? activeButtonFont
? activeButtonFont
: activeButtonFont = YFont::getFont(activeWorkspaceFontName)
: YButton::getFont()
: *normalWorkspaceFontName
? normalButtonFont
? normalButtonFont
: normalButtonFont = YFont::getFont(normalWorkspaceFontName)
: YButton::getFont();
}
YColor * WorkspaceButton::getColor() {
return isPressed()
? *clrWorkspaceActiveButtonText
? activeButtonFg
? activeButtonFg
: activeButtonFg = new YColor(clrWorkspaceActiveButtonText)
: YButton::getColor()
: *clrWorkspaceNormalButtonText
? normalButtonFg
? normalButtonFg
: normalButtonFg = new YColor(clrWorkspaceNormalButtonText)
: YButton::getColor();
}
YSurface WorkspaceButton::getSurface() {
if (activeButtonBg == 0)
activeButtonBg = new YColor(*clrWorkspaceActiveButton
? clrWorkspaceActiveButton : clrActiveButton);
if (normalButtonBg == 0)
normalButtonBg = new YColor(*clrWorkspaceNormalButton
? clrWorkspaceNormalButton : clrNormalButton);
#ifdef CONFIG_GRADIENTS
return (isPressed() ? YSurface(activeButtonBg,
workspacebuttonactivePixmap,
workspacebuttonactivePixbuf)
: YSurface(normalButtonBg,
workspacebuttonPixmap,
workspacebuttonPixbuf));
#else
return (isPressed() ? YSurface(activeButtonBg, workspacebuttonactivePixmap)
: YSurface(normalButtonBg, workspacebuttonPixmap));
#endif
}
#endif