[go: up one dir, main page]

Menu

[12172e]: / src / wmstatus.cc  Maximize  Restore  History

Download this file

207 lines (162 with data), 5.8 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
201
202
203
204
205
206
/*
* IceWM
*
* Copyright (C) 1997-2001 Marko Macek
*
* Status display for resize/move
*/
#include "config.h"
#ifndef LITE
#include "yfull.h"
#include "wmstatus.h"
#include "wmswitch.h" // !!! remove (for bg pixmap)
#include "wmframe.h"
#include "wmclient.h"
#include "wmmgr.h"
#include "prefs.h"
#include "intl.h"
#include <stdio.h>
#include <string.h>
YColor *YWindowManagerStatus::statusFg = 0;
YColor *YWindowManagerStatus::statusBg = 0;
YFont *YWindowManagerStatus::statusFont = 0;
MoveSizeStatus *statusMoveSize = 0;
WorkspaceStatus *statusWorkspace = 0;
/******************************************************************************/
/******************************************************************************/
YWindowManagerStatus::YWindowManagerStatus(YWindow *aParent,
const char *(*templFunc)())
: YWindow(aParent) {
if (statusBg == 0)
statusBg = new YColor(clrMoveSizeStatus);
if (statusFg == 0)
statusFg = new YColor(clrMoveSizeStatusText);
if (statusFont == 0)
statusFont = YFont::getFont(statusFontName);
int sW = statusFont->textWidth(templFunc());
int sH = statusFont->height();
setGeometry((manager->width() - sW) / 2,
(manager->height() - sH) - 8, // / 2,
sW + 2, sH + 4);
setStyle(wsOverrideRedirect);
}
YWindowManagerStatus::~YWindowManagerStatus() {
}
void YWindowManagerStatus::paint(Graphics &g, int /*x*/, int /*y*/,
unsigned int /*width*/,
unsigned int /*height*/) {
const char *status;
g.setColor(statusBg);
g.drawBorderW(0, 0, width() - 1, height() - 1, true);
if (switchbackPixmap)
g.fillPixmap(switchbackPixmap, 1, 1, width() - 3, height() - 3);
else
g.fillRect(1, 1, width() - 3, height() - 3);
g.setColor(statusFg);
g.setFont(statusFont);
status = getStatus();
g.drawChars(status, 0, strlen(status),
width() / 2 - statusFont->textWidth(status) / 2,
height() - statusFont->descent() - 2);
}
void YWindowManagerStatus::begin() {
setPosition(x(),
#ifdef CONFIG_TASKBAR
taskBarAtTop ? 4 :
#endif
(manager->height() - height()) - 4);
raise();
show();
}
/******************************************************************************/
/******************************************************************************/
MoveSizeStatus::MoveSizeStatus(YWindow *aParent)
: YWindowManagerStatus(aParent, templateFunction) {
}
MoveSizeStatus::~MoveSizeStatus() {
}
const char* MoveSizeStatus::getStatus() {
static char status[50];
sprintf(status, "%dx%d+%d+%d", fW, fH, fX, fY);
return status;
}
void MoveSizeStatus::begin(YFrameWindow *frame) {
if (showMoveSizeStatus) {
setStatus(frame);
YWindowManagerStatus::begin();
}
}
void MoveSizeStatus::setStatus(YFrameWindow *frame, int x, int y, int width, int height) {
XSizeHints *sh = frame->client()->sizeHints();
width -= frame->borderX() * 2;
height -= frame->borderY() * 2 + frame->titleY();
fX = x;//// + frame->borderX ();
fY = y;//// + frame->borderY () + frame->titleY ();
fW = (width - (sh ? sh->base_width : 0)) / (sh ? sh->width_inc : 1);
fH = (height - (sh ? sh->base_height : 0)) / (sh ? sh->height_inc : 1);
repaint ();
}
void MoveSizeStatus::setStatus(YFrameWindow *frame) {
XSizeHints *sh = frame->client()->sizeHints();
fX = frame->x ();//// + frame->borderX ();
fY = frame->y ();//// + frame->borderY () + frame->titleY ();
fW = (frame->client()->width() - (sh ? sh->base_width : 0)) / (sh ? sh->width_inc : 1);
fH = (frame->client()->height() - (sh ? sh->base_height : 0)) / (sh ? sh->height_inc : 1);
repaint ();
}
const char* MoveSizeStatus::templateFunction() {
return "9999x9999+9999+9999";
}
/******************************************************************************/
/******************************************************************************/
class WorkspaceStatusTimeout: public YTimerListener {
public:
virtual bool handleTimer(YTimer */*timer*/) {
statusWorkspace->end();
return false;
}
};
/******************************************************************************/
WorkspaceStatus::WorkspaceStatus(YWindow *aParent)
: YWindowManagerStatus(aParent, templateFunction) {
// !!! read timeout from preferences
timer = new YTimer(workspaceStatusTime);
timer->setTimerListener(new WorkspaceStatusTimeout());
}
WorkspaceStatus::~WorkspaceStatus() {
delete timer;
}
const char* WorkspaceStatus::getStatus() {
return getStatus(manager->workspaceName(workspace));
}
const char* WorkspaceStatus::getStatus(const char* name) {
static char *namebuffer = NULL;
if (namebuffer) delete [] namebuffer;
namebuffer = strJoin(_("Workspace: "), name, NULL);
return namebuffer;
}
void WorkspaceStatus::begin(long workspace) {
setStatus(workspace);
YWindowManagerStatus::begin();
}
void WorkspaceStatus::setStatus(long workspace) {
this->workspace = workspace;
repaint();
if (timer->isRunning())
timer->stopTimer();
timer->startTimer();
}
const char* WorkspaceStatus::templateFunction() {
const char* longestWorkspaceName = NULL;
int maxWorkspaceNameLength = 0;
for (long w = 0; w < manager->workspaceCount(); ++w) {
const char* name = manager->workspaceName(w);
int length = statusFont->textWidth(name);
if (length > maxWorkspaceNameLength) {
maxWorkspaceNameLength = length;
longestWorkspaceName = name;
}
}
return getStatus(longestWorkspaceName);
}
#endif