~ubuntu-branches/ubuntu/trusty/miwm/trusty

« back to all changes in this revision

Viewing changes to wspace.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jari Aalto
  • Date: 2010-01-04 15:25:34 UTC
  • Revision ID: james.westby@ubuntu.com-20100104152534-l3fdvt162le460cv
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//-*-c++-*-
 
2
// -------------------------------------------
 
3
// RCS data:
 
4
// $Date: 2003/07/04 10:12:01 $
 
5
// $Revision: 1.3 $
 
6
// $Source: /cvsroot/miwm/miwm/miwm/wspace.cc,v $
 
7
// $Id: wspace.cc,v 1.3 2003/07/04 10:12:01 sgbeal Exp $
 
8
// $RCSfile: wspace.cc,v $
 
9
// -------------------------------------------
 
10
// Copyright by Ben Paul Wise.
 
11
// -------------------------------------------
 
12
// This program is free software; you can redistribute it and/or modify
 
13
// it under the terms of the GNU General Public License as published by
 
14
// the Free Software Foundation; either version 2 of the License, or
 
15
// (at your option) any later version.
 
16
// 
 
17
// This program is distributed in the hope that it will be useful,
 
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
// GNU General Public License for more details.
 
21
// 
 
22
// You should have received a copy of the GNU General Public License
 
23
// along with this program; if not, write to the Free Software
 
24
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
25
// -------------------------------------------
 
26
// this defines the functions for workspace-related
 
27
// manipulations
 
28
// -------------------------------------------
 
29
 
 
30
#include "miwm.h"
 
31
#include "ws.h"
 
32
#include "miwm_framework.h"
 
33
#include "EStringList.h"
 
34
 
 
35
// -------------------------------------------
 
36
 
 
37
void
 
38
WindowManager::setupWS() {
 
39
 
 
40
        numWorkSpaces = 0;
 
41
        allWorkSpaces = (WorkSpace**) malloc (maxNumWorkSpaces * sizeof (WorkSpace));
 
42
        previewWSP = 0;
 
43
        previewedWorkSpace = NULL; // and likely to stay that way
 
44
  
 
45
        std::string spacenames = miwm::config().getString( "workspace_names", "One Two Three Four Five Six" );
 
46
        EStringList list = EStringList::tokenize( spacenames );
 
47
        std::string wsname;
 
48
        while( true )
 
49
        {
 
50
                wsname = list.shift();
 
51
                if( wsname.empty() ) break;
 
52
                addWorkSpace( wsname.c_str() );
 
53
        }
 
54
  return;
 
55
}
 
56
 
 
57
 
 
58
void
 
59
WindowManager::addWorkSpace(const char* wsName) {
 
60
 
 
61
  if (numWorkSpaces < maxNumWorkSpaces) {
 
62
  WorkSpace* ws = new WorkSpace(wsName);
 
63
  allWorkSpaces[numWorkSpaces] = ws;
 
64
  numWorkSpaces = numWorkSpaces + 1;
 
65
  if (1 == numWorkSpaces)
 
66
    workSpace = ws;
 
67
  }
 
68
  else {
 
69
    cout << "Maximum number of workspaces ("<<maxNumWorkSpaces<<") reached." << endl;
 
70
    cout << "Therefore, workspace " << wsName<<" will not be added"<<endl;
 
71
    cout << flush;
 
72
  }
 
73
  return;
 
74
}
 
75
 
 
76
// -------------------------------------------
 
77
 
 
78
// I defocus everything right before moving it off screen, for two reasons.
 
79
// First: if I did not, things that were in focus but are now
 
80
// offscreen get redrawn (with defocused border) when I set focus in
 
81
// the new workspace.
 
82
// Second: it prevents things like offscreen-xterms from accidentally
 
83
// getting keyboard input, doing deletes in the wrong directory, etc.
 
84
 
 
85
void 
 
86
WindowManager::changeWorkSpace(WorkSpace* ws1, WorkSpace* ws2) {
 
87
  Node* cND = NULL;
 
88
  Client* c = NULL;
 
89
  assert (NULL != ws1);
 
90
  assert (NULL != ws2);
 
91
  if (ws1 == ws2)
 
92
    return;
 
93
 
 
94
  for (cND = allClients->first; cND != NULL; cND = allClients->nextNode(cND)) {
 
95
    c = ((Client*) cND->data);
 
96
 
 
97
    // if this client is NULL, we are in deep doo doo
 
98
    assert (NULL != c);
 
99
 
 
100
 
 
101
    if (c->workSpace == ws1)  {
 
102
      // I marked the following 'if' as suspicious,
 
103
      // but now I don't recall why
 
104
      if (False == c->hidden)
 
105
        if (c->sticky == 0)  {
 
106
          if (c == current) {
 
107
            setactive(current , 0 , 0L); 
 
108
            current = NULL;
 
109
          }
 
110
          innerSendClienttoWS(c, 0); // hide it
 
111
        }
 
112
        else { // c->sticky == 1
 
113
          c->workSpace = ws2;
 
114
        }
 
115
    }
 
116
 
 
117
    if (c->workSpace == ws2)  {
 
118
      if (c->sticky == 0)  {
 
119
        if (False == c->hidden)
 
120
          innerSendClienttoWS(c, 1);  // actually show it
 
121
      }
 
122
      else  { 
 
123
        // do nothing: it is sticky and already in this WS
 
124
      }
 
125
    }
 
126
 
 
127
  }
 
128
  workSpace = ws2;
 
129
  focusOn(NULL); // arrive defocused
 
130
  return;
 
131
}
 
132
 
 
133
void 
 
134
WindowManager::sendClientToWorkSpace(Client* client, WorkSpace* ws2) {
 
135
  assert (NULL != ws2);
 
136
  if (NULL != client) { // client did not die during the operation
 
137
    if ((ws2 != workSpace) || (ws2 != client->workSpace)) {
 
138
      client->sticky = 0;
 
139
      client->workSpace = ws2;
 
140
  
 
141
      // is this one in focus?
 
142
      if (client == current) {
 
143
        setactive(current, 0, 0L); // copied from disp.cc
 
144
        current = NULL;
 
145
      }
 
146
 
 
147
      innerSendClienttoWS(client, 0); // make it invisible
 
148
    }
 
149
    assert (client->workSpace == ws2);
 
150
 
 
151
    if (1 == followClientToWS) {
 
152
      changeWorkSpace(workSpace, client->workSpace);
 
153
      followClientToWS = 0;
 
154
    }
 
155
  }
 
156
  else { // client died during the operation. CYA
 
157
    XUnmapWindow(dpy, popup);
 
158
    mode =   wmReady;
 
159
  }
 
160
 
 
161
  return;
 
162
}
 
163
 
 
164
void
 
165
WindowManager::innerSendClienttoWS(Client* client, int visibleP) {
 
166
 
 
167
  if (visibleP == 0)  {// slide it away
 
168
    //  set normalX, normalY just prior to pushing it off the screen.
 
169
    client->normalX = client->size.x;
 
170
    client->normalY = client->size.y;
 
171
    client->normalW = client->size.width;
 
172
    client->normalH = client->size.height;
 
173
 
 
174
    XMoveWindow(dpy, client->parent,
 
175
                client->size.x + offWorkSpace, 
 
176
                client->size.y + offWorkSpace);
 
177
    // note that I do not do any configure notification.
 
178
    // if the client pops up an emergency dialog box, I want it to show.
 
179
  }
 
180
  else {  // slide it back
 
181
    XMoveWindow(dpy, client->parent,
 
182
                client->normalX, 
 
183
                client->normalY);
 
184
    //         XMapWindow(dpy, client->parent);
 
185
  }
 
186
  return;
 
187
}
 
188
 
 
189
// -------------------------------------------
 
190
 
 
191
WorkSpace::WorkSpace(const char* n) {
 
192
  label = string(n);
 
193
}
 
194
 
 
195
 
 
196
WorkSpace::~WorkSpace() {
 
197
//   XtFree(label);
 
198
}
 
199
 
 
200
void 
 
201
WindowManager::rotateWSClients() {
 
202
  Client *c1 = current;
 
203
  Client *c2 = NULL;
 
204
  Node* cND = NULL;
 
205
  int i = 0;
 
206
  int numClients = allClients->length() ;
 
207
  
 
208
 
 
209
  if (0 == numClients)
 
210
    return;
 
211
 
 
212
  if (c1 == NULL) {
 
213
    cND = allClients->first;
 
214
    c1 = ((Client*) cND->data);
 
215
  }
 
216
 
 
217
  cND = allClients->inList(c1);
 
218
 
 
219
  while ((c2 == NULL) && ( i < numClients + 2)) {
 
220
    cND = allClients->nextNode(cND);
 
221
    if (cND == NULL)
 
222
      cND = allClients->first;
 
223
    i = i + 1;
 
224
 
 
225
    c1 = ((Client*) cND->data);
 
226
 
 
227
    // if this client is NULL, we are in deep doo doo
 
228
    assert (NULL != c1);
 
229
 
 
230
 
 
231
    if ((False == c1->hidden) && (workSpace == c1->workSpace))
 
232
      c2 = c1;
 
233
  }
 
234
 
 
235
  if (c2 != NULL) {
 
236
    raiseClient(c2);
 
237
    focusOn(c2);
 
238
  }
 
239
 
 
240
  return;
 
241
}
 
242
// -------------------------------------------
 
243
// end of wspace.cc
 
244
// -------------------------------------------
 
245