File: wspace.cc

package info (click to toggle)
miwm 1.1-6
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,296 kB
  • ctags: 910
  • sloc: cpp: 8,179; sh: 231; makefile: 148
file content (247 lines) | stat: -rw-r--r-- 6,510 bytes parent folder | download | duplicates (5)
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
//-*-c++-*-
// -------------------------------------------
// RCS data:
// $Date: 2003/07/04 10:12:01 $
// $Revision: 1.3 $
// $Source: /cvsroot/miwm/miwm/miwm/wspace.cc,v $
// $Id: wspace.cc,v 1.3 2003/07/04 10:12:01 sgbeal Exp $
// $RCSfile: wspace.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.
// -------------------------------------------
// this defines the functions for workspace-related
// manipulations
// -------------------------------------------

#include "miwm.h"
#include "ws.h"
#include "miwm_framework.h"
#include "EStringList.h"

// -------------------------------------------

void
WindowManager::setupWS() {

        numWorkSpaces = 0;
        allWorkSpaces = (WorkSpace**) malloc (maxNumWorkSpaces * sizeof (WorkSpace));
        previewWSP = 0;
        previewedWorkSpace = NULL; // and likely to stay that way
  
        std::string spacenames = miwm::config().getString( "workspace_names", "One Two Three Four Five Six" );
        EStringList list = EStringList::tokenize( spacenames );
        std::string wsname;
        while( true )
        {
                wsname = list.shift();
                if( wsname.empty() ) break;
                addWorkSpace( wsname.c_str() );
        }
  return;
}


void
WindowManager::addWorkSpace(const char* wsName) {

  if (numWorkSpaces < maxNumWorkSpaces) {
  WorkSpace* ws = new WorkSpace(wsName);
  allWorkSpaces[numWorkSpaces] = ws;
  numWorkSpaces = numWorkSpaces + 1;
  if (1 == numWorkSpaces)
    workSpace = ws;
  }
  else {
    cout << "Maximum number of workspaces ("<<maxNumWorkSpaces<<") reached." << endl;
    cout << "Therefore, workspace " << wsName<<" will not be added"<<endl;
    cout << flush;
  }
  return;
}

// -------------------------------------------

// I defocus everything right before moving it off screen, for two reasons.
// First: if I did not, things that were in focus but are now
// offscreen get redrawn (with defocused border) when I set focus in
// the new workspace.
// Second: it prevents things like offscreen-xterms from accidentally
// getting keyboard input, doing deletes in the wrong directory, etc.

void 
WindowManager::changeWorkSpace(WorkSpace* ws1, WorkSpace* ws2) {
  Node* cND = NULL;
  Client* c = NULL;
  assert (NULL != ws1);
  assert (NULL != ws2);
  if (ws1 == ws2)
    return;

  for (cND = allClients->first; cND != NULL; cND = allClients->nextNode(cND)) {
    c = ((Client*) cND->data);

    // if this client is NULL, we are in deep doo doo
    assert (NULL != c);


    if (c->workSpace == ws1)  {
      // I marked the following 'if' as suspicious,a
      // but now I don't recall why
      if (False == c->hidden)
      {
	if (c->sticky == 0)  {
	  if (c == current) {
	    setactive(current , 0 , 0L); 
	    current = NULL;
	  }
	  innerSendClienttoWS(c, 0); // hide it
	}
	else { // c->sticky == 1
	  c->workSpace = ws2;
	}
      }
    }

    if (c->workSpace == ws2)  {
      if (c->sticky == 0)  {
 	if (False == c->hidden)
	  innerSendClienttoWS(c, 1);  // actually show it
      }
      else  { 
	// do nothing: it is sticky and already in this WS
      }
    }

  }
  workSpace = ws2;
  focusOn(NULL); // arrive defocused
  return;
}

void 
WindowManager::sendClientToWorkSpace(Client* client, WorkSpace* ws2) {
  assert (NULL != ws2);
  if (NULL != client) { // client did not die during the operation
    if ((ws2 != workSpace) || (ws2 != client->workSpace)) {
      client->sticky = 0;
      client->workSpace = ws2;
  
      // is this one in focus?
      if (client == current) {
	setactive(current, 0, 0L); // copied from disp.cc
	current = NULL;
      }

      innerSendClienttoWS(client, 0); // make it invisible
    }
    assert (client->workSpace == ws2);

    if (1 == followClientToWS) {
      changeWorkSpace(workSpace, client->workSpace);
      followClientToWS = 0;
    }
  }
  else { // client died during the operation. CYA
    XUnmapWindow(dpy, popup);
    mode =   wmReady;
  }

  return;
}

void
WindowManager::innerSendClienttoWS(Client* client, int visibleP) {

  if (visibleP == 0)  {// slide it away
    //  set normalX, normalY just prior to pushing it off the screen.
    client->normalX = client->size.x;
    client->normalY = client->size.y;
    client->normalW = client->size.width;
    client->normalH = client->size.height;

    XMoveWindow(dpy, client->parent,
		client->size.x + offWorkSpace, 
		client->size.y + offWorkSpace);
    // note that I do not do any configure notification.
    // if the client pops up an emergency dialog box, I want it to show.
  }
  else {  // slide it back
    XMoveWindow(dpy, client->parent,
		client->normalX, 
		client->normalY);
    //         XMapWindow(dpy, client->parent);
  }
  return;
}

// -------------------------------------------

WorkSpace::WorkSpace(const char* n) {
  label = string(n);
}


WorkSpace::~WorkSpace() {
//   XtFree(label);
}

void 
WindowManager::rotateWSClients() {
  Client *c1 = current;
  Client *c2 = NULL;
  Node* cND = NULL;
  int i = 0;
  int numClients = allClients->length() ;
  

  if (0 == numClients)
    return;

  if (c1 == NULL) {
    cND = allClients->first;
    c1 = ((Client*) cND->data);
  }

  cND = allClients->inList(c1);

  while ((c2 == NULL) && ( i < numClients + 2)) {
    cND = allClients->nextNode(cND);
    if (cND == NULL)
      cND = allClients->first;
    i = i + 1;

    c1 = ((Client*) cND->data);

    // if this client is NULL, we are in deep doo doo
    assert (NULL != c1);


    if ((False == c1->hidden) && (workSpace == c1->workSpace))
      c2 = c1;
  }

  if (c2 != NULL) {
    raiseClient(c2);
    focusOn(c2);
  }

  return;
}
// -------------------------------------------
// end of wspace.cc
// -------------------------------------------