2
2
#include <assert.h>
3
3
#include <string.h>
4
4
#include <stdio.h>
5
+ #include <stdlib.h>
5
6
#include <X11/Xlib.h>
6
7
7
8
#include "structs.h"
@@ -46,7 +47,7 @@ void logMessage(char message[]) {
46
47
display ,
47
48
statusWindow ,
48
49
DefaultGC (display , activeScreen ),
49
- 15 , 15 ,
50
+ 16 , 15 ,
50
51
message , strlen (message )
51
52
);
52
53
}
@@ -132,15 +133,21 @@ void raiseWindow(Window *window){
132
133
}
133
134
134
135
void dumpWorkspace (int wn ) {
135
- int i ;
136
- for (i = 0 ; i <= workspaces [wn ].lastElement ; i ++ ) {
137
- fprintf (stderr , "Workspaces %d has Window %d\n" , wn , & workspaces [wn ].windows [i ]);
136
+ int run = 1 ;
137
+
138
+ Client * cp ;
139
+
140
+ for (cp = workspaces [wn ].last ; cp ; cp = cp -> previous ) {
141
+ fprintf (stderr , "Client pointer %d\n" , cp );
138
142
}
143
+
144
+
139
145
}
140
146
141
147
int changeWorkspace (int workspace ) {
142
148
//Trying to change to the current workspace
143
149
if (workspace == currentWorkspace ) { return False ; }
150
+ dumpWorkspace (workspace );
144
151
145
152
int wksp ;
146
153
for (wksp = 0 ; wksp <= workspaces [workspace ].lastElement ; wksp ++ ) {
@@ -158,18 +165,28 @@ int changeWorkspace(int workspace) {
158
165
* --------------------------- */
159
166
void hMapRequest (XEvent * event ) {
160
167
logMessage ("Map Request" );
168
+ fprintf (stderr , "Mapping request %d\n" , event -> xmaprequest .serial );
169
+
170
+ //Create Pointer to new Client struct and put window inside
171
+ //Set the Client's previous pointer to the last client added to workspace
172
+ //Now set the workspace's last client pointer to the new client!
173
+ Client * newClient ;
174
+ newClient = malloc (sizeof (Client ));
175
+ newClient -> window = event -> xmaprequest .window ;
176
+ newClient -> previous = workspaces [currentWorkspace ].last ;
177
+ workspaces [currentWorkspace ].last = newClient ;
161
178
162
- //Map the Window
163
- Window mapRequestWindow = event -> xmaprequest .window ;
164
- XMapWindow (display , mapRequestWindow );
179
+ //Map
180
+ XMapWindow (display , newClient -> window );
165
181
166
- workspaces [currentWorkspace ].windows [workspaces [currentWorkspace ].lastElement ] = mapRequestWindow ;
182
+ workspaces [currentWorkspace ].windows [workspaces [currentWorkspace ].lastElement ] = newClient -> window ;
167
183
workspaces [currentWorkspace ].lastElement ++ ;
168
184
185
+
169
186
//Window Fns: Raise, Border, Center Pointer, Setup Events
170
- raiseWindow ( & mapRequestWindow );
171
- applyBorder ( & mapRequestWindow , unfocusedColor );
172
- centerPointer (& mapRequestWindow );
187
+ raiseWindow ( & ( newClient -> window ) );
188
+ applyBorder ( & ( newClient -> window ) , unfocusedColor );
189
+ centerPointer (& ( newClient -> window ) );
173
190
}
174
191
175
192
void hConfigureRequest (XEvent * event ) {
@@ -376,6 +393,8 @@ int main() {
376
393
display = XOpenDisplay (NIL );
377
394
assert (display );
378
395
396
+ memset (& workspaces , 0x00 , sizeof (Workspace )* 10 );
397
+
379
398
//Setup the Root Window, Active Screen, and Events
380
399
root = RootWindow (display , activeScreen );
381
400
activeScreen = DefaultScreen (display );
0 commit comments