Skip to content

Commit cba035e

Browse files
author
Miles Sandlar
committed
Adding of Client structure. Workspace stores *last
Working toward looping through pointers / eliminating windows array
1 parent 7cdf40f commit cba035e

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

simple-wm.c

+30-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <assert.h>
33
#include <string.h>
44
#include <stdio.h>
5+
#include <stdlib.h>
56
#include <X11/Xlib.h>
67

78
#include "structs.h"
@@ -46,7 +47,7 @@ void logMessage(char message[]) {
4647
display,
4748
statusWindow,
4849
DefaultGC(display, activeScreen),
49-
15, 15,
50+
16, 15,
5051
message, strlen(message)
5152
);
5253
}
@@ -132,15 +133,21 @@ void raiseWindow(Window *window){
132133
}
133134

134135
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);
138142
}
143+
144+
139145
}
140146

141147
int changeWorkspace(int workspace) {
142148
//Trying to change to the current workspace
143149
if (workspace == currentWorkspace) { return False; }
150+
dumpWorkspace(workspace);
144151

145152
int wksp;
146153
for (wksp = 0; wksp <= workspaces[workspace].lastElement; wksp++) {
@@ -158,18 +165,28 @@ int changeWorkspace(int workspace) {
158165
* --------------------------- */
159166
void hMapRequest(XEvent *event) {
160167
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;
161178

162-
//Map the Window
163-
Window mapRequestWindow = event -> xmaprequest.window;
164-
XMapWindow(display, mapRequestWindow);
179+
//Map
180+
XMapWindow(display, newClient -> window);
165181

166-
workspaces[currentWorkspace].windows[workspaces[currentWorkspace].lastElement] = mapRequestWindow;
182+
workspaces[currentWorkspace].windows[workspaces[currentWorkspace].lastElement] = newClient -> window;
167183
workspaces[currentWorkspace].lastElement++;
168184

185+
169186
//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) );
173190
}
174191

175192
void hConfigureRequest(XEvent *event) {
@@ -376,6 +393,8 @@ int main() {
376393
display = XOpenDisplay(NIL);
377394
assert(display);
378395

396+
memset(&workspaces, 0x00, sizeof(Workspace)*10);
397+
379398
//Setup the Root Window, Active Screen, and Events
380399
root = RootWindow(display, activeScreen);
381400
activeScreen = DefaultScreen(display);

structs.h

+9
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@ typedef struct {
77
int y;
88
} PointerMotion;
99

10+
//Inspired by DWM
11+
typedef struct Client Client;
12+
struct Client {
13+
Window window;
14+
Bool isFocused;
15+
Client *previous;
16+
};
17+
1018
typedef struct {
1119
Window active;
1220
Window windows[20];
21+
Client *last;
1322
int lastElement;
1423
} Workspace;

0 commit comments

Comments
 (0)