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 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
//-*-c++-*-
// ----------------------------------------------
// RCS data:
// $Date: 2003/07/04 09:48:55 $
// $Revision: 1.3 $
// $Source: /cvsroot/miwm/miwm/miwm/ops.cc,v $
// $Id: ops.cc,v 1.3 2003/07/04 09:48:55 sgbeal Exp $
// $RCSfile: ops.cc,v $
// ----------------------------------------------
// Copyright by Ben Paul Wise.
// -------------------------------------------
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
// ----------------------------------------------
// simple window management operations
// ----------------------------------------------
#include "miwm.h"
#include "miwm_framework.h"
// ----------------------------------------------
void
toggleRaiseOnFocus() {
if (1 == theWM->raiseOnFocusP)
theWM->raiseOnFocusP = 0;
else
theWM->raiseOnFocusP = 1;
miwm::config().set( "raise_client_on_focus", theWM->raiseOnFocusP );
return;
}
void
toggleTopLeft() {
if (1 == theWM->protectTopLeft)
theWM->protectTopLeft = 0;
else
theWM->protectTopLeft = 1;
return;
}
void
toggleClientPreview() {
if (1 == theWM->previewCP)
theWM->previewCP = 0;
else
theWM->previewCP = 1;
miwm::config().set( "preview_client_before_unhide", theWM->previewCP );
return;
}
void toggleTiling() {
if (1 == theWM->tileP)
theWM->tileP = 0;
else
theWM->tileP = 1;
return;
}
void togglePixmaps() {
#ifdef USE_PIXMAPS
XSetWindowAttributes attr;
switch (theWM->usePixmapsP) {
case 1:
theWM->usePixmapsP = 0;
attr.background_pixmap = None;
XChangeWindowAttributes(dpy, popup, CWBackPixmap , &attr);
XSetWindowBackground(dpy, popup, theWM->inactiveBorderColor.pixel);
break;
case 0:
theWM->usePixmapsP = 1;
attr.background_pixmap = theWM->popupBgd;
XChangeWindowAttributes(dpy, popup, CWBackPixmap , &attr);
break;
default:
break;
}
miwm::config().set( "enable_pixmaps", theWM->usePixmapsP );
#endif
return;
}
void rotateClients() {
theWM->rotateWSClients();
return;
}
void terminateWM() {
Terminate(0);
return;
}
void contractWS() {
WorkSpace *home = theWM->allWorkSpaces[0];
Node* cND;
Client* c;
int i;
// cycle through workspaces, unhiding things
for (i = 0; i<theWM->numWorkSpaces; i++) {
theWM->changeWorkSpace(theWM->workSpace, theWM->allWorkSpaces[i]);
for (cND = theWM->allClients->first;
cND != NULL;
cND = theWM->allClients->nextNode(cND)) {
c = ((Client*) cND->data);
// if this client is NULL, we are in deep doo doo
assert (NULL != c);
if (hidden(c))
unhidec(c,1);
}
}
// cycle through workspaces, sending each client home
for (i = 0; i<theWM->numWorkSpaces; i++) {
theWM->changeWorkSpace(theWM->workSpace, theWM->allWorkSpaces[i]);
for (cND = theWM->allClients->first;
cND != NULL;
cND = theWM->allClients->nextNode(cND)) {
c = ((Client*) cND->data);
// if this client is NULL, we are in deep doo doo
assert (NULL != c);
theWM->sendClientToWorkSpace(c, home);
}
}
// finally, WM goes home
theWM->changeWorkSpace(theWM->workSpace, home);
// try to clean up the resulting mess !
retileWS();
return;
}
void stepWSup() {
stepWS(+1);
return;
}
void stepWS(int step) {
assert ((+1 == step) || (-1 == step));
int i = 0;
int j = -1;
WorkSpace* ws1 = theWM->workSpace;
WorkSpace* ws2 = NULL;
for (i=0; ((-1 == j) && (i<theWM->numWorkSpaces)); i++)
if (theWM->allWorkSpaces[i] == ws1) {
j = i;
}
// ensure it is positive,
step = step + theWM->numWorkSpaces;
j = (j+step) % theWM->numWorkSpaces;
ws2 = theWM->allWorkSpaces[j];
theWM->changeWorkSpace(ws1, ws2);
return;
}
void retileWS() {
Node* cND;
NodeList* remaining = new NodeList();
Client* c;
Client* bigC;
int largestArea = 0;
int area = 0;
int oldTiling = theWM->tileP;
theWM->tileP = 1;
theWM->auto_x = 1;
theWM->auto_y = 1;
if (current != NULL) {
setactive(current, 0, 0L);
current = NULL;
}
// find every non-sticky client in the current workspace,
// and shift their coordinates out of the way
// it is a good idea to put sticky things on the bottom or right edges)
for (cND = theWM->allClients->first;
cND != NULL;
cND = theWM->allClients->nextNode(cND)) {
c = ((Client*) cND->data);
// if this client is NULL, we are in deep doo doo
assert (NULL != c);
if ((c->sticky == 0)
&& (c->workSpace == theWM->workSpace)
&& (False == c->hidden)
&& (1 == c->isMapped)
)
{
remaining->append((void*)c);
c->size.x = c->size.x + theWM->offWorkSpace;
}
}
// re-place them in largest-first order.
while (remaining->length() > 0) {
largestArea = 0;
bigC = NULL;
for (cND = remaining->first;
cND != NULL;
cND = remaining->nextNode(cND)) {
c = ((Client*) cND->data);
area = c->size.width * c->size.height;
if (area > largestArea) {
largestArea = area;
bigC = c;
}
}
theWM->autoPlaceCoords(bigC);
XMoveWindow(dpy, bigC->parent, bigC->size.x, bigC->size.y);
sendConfigureNotify(bigC);
// ensure the last are on top of the first-placed large ones
if (1 == bigC->isMapped)
theWM->raiseClient(bigC);
cND = remaining->inList((void*) bigC);
assert (NULL != cND);
remaining->remove(cND);
}
delete remaining;
remaining = NULL;
theWM->auto_x = 5;
theWM->auto_y = 5;
theWM->tileP = oldTiling;
return;
}
void restartWM() {
char* sh = ((char*) getenv("SHELL"));
char default_sh[] = "/bin/sh";
if (sh == 0)
sh = default_sh;
int rslt = fork();
switch (rslt) {
case 0: // child
close(ConnectionNumber(dpy));
execl(sh, sh, "-c", "miwm", 0);
break;
case -1: // error
XBell(dpy, 70);
fprintf(stderr, "miwm: restart failed (errno %d)\n", errno);
exit(1);
break;
default: // parent
Terminate(0);
break;
}
return;
}
void idCurrent() {
if (NULL != current) {
cout << "Current client is " << current->clientID <<endl;
cout << "Hidden: " << current->hidden << endl;
cout << "isMapped: " << current->isMapped << endl;
}
else { // client died during the operation. CYA
cout << "Current client is NULL"<<endl;
}
return;
}
void terminateCurrent() {
if (NULL != current)
closeClient(current);
else { // client died during the operation. CYA
cout << "Current client is NULL"<<endl;
}
return;
}
void toggleSticky() {
if (NULL != current)
current->sticky = 1- current->sticky;
else { // client died during the operation. CYA
cout << "Current client is NULL"<<endl;
}
return;
}
// ----------------------------------------------
// end of ops.cc
// ----------------------------------------------
|