-
Notifications
You must be signed in to change notification settings - Fork 0
/
reparent.c
128 lines (116 loc) · 3.85 KB
/
reparent.c
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
/* implementation file for
* reparenting windows when they send a map request
* (want to be displayed on the screen) */
#include "reparent.h"
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
// counter and Windows to be used as window borders
int frames_index=0;
Window frames[10];
/* creates a frame for the input child window and reparents
* it to the created frame */
Bool reparent_window(Display *d, Window child, Bool before_wm)
{
XWindowAttributes a; // get info about the child window to create
// its border
/* moved as defines in reparent.h; used to resize windows */
//const int border_width = 2; // border size of the parent window
//const int title_height = 20; // size of the title bar
/* get child information */
XGetWindowAttributes(d, child, &a);
/* exit if we have too many windows cuz no linked list yet */
if(frames_index >= 10){
fprintf(stderr, "MORE THAN 10 Windows AAAAHHH!\n");
exit(0);
}
/* create the border window */
frames[frames_index] = XCreateSimpleWindow(d, // Display *d
RootWindow(d, DefaultScreen(d)), // Display *parent
0, // x coord
0, // y coord
a.width+(BORDER_WIDTH), // window width
a.height+TITLE_HEIGHT, // window height
BORDER_WIDTH, // border size
WhitePixel(d, DefaultScreen(d)), // border
BlackPixel(d, DefaultScreen(d))); // background
/* select events on the frame */
XSelectInput( d,
frames[frames_index],
SubstructureRedirectMask | SubstructureNotifyMask );
/* restores the child if we crash somehow */
XAddToSaveSet(d, child);
/* assuming last thing needed to do */
XReparentWindow(d, // Display *d
child, // Window w
frames[frames_index], // Window parent
//BORDER_WIDTH-(BORDER_WIDTH/2), // int x - x position in new parent window
0, // int x - x position in new parent window
TITLE_HEIGHT); // int y - y position in new parent window
/*
// 9. Grab universal window management actions on client window.
// a. Move windows with alt + left button.
XGrabButton(
d,
Button1,
Mod1Mask,
child,
False,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask,
GrabModeAsync,
GrabModeAsync,
None,
None);
// b. Resize windows with alt + right button.
XGrabButton(
d,
Button3,
Mod1Mask,
child,
False,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask,
GrabModeAsync,
GrabModeAsync,
None,
None);
// c. Kill windows with alt + f4.
XGrabKey(
d,
XKeysymToKeycode(d, XK_F4),
Mod1Mask,
child,
False,
GrabModeAsync,
GrabModeAsync);
// d. Switch windows with alt + tab.
XGrabKey(
d,
XKeysymToKeycode(d, XK_Tab),
Mod1Mask,
child,
False,
GrabModeAsync,
GrabModeAsync);
*/
// Grab input to frame
XGrabButton(
d,
1,
None,
frames[frames_index],
//False,
True,
//ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | PointerMotionMask,
//ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync,
GrabModeAsync,
//None,
frames[frames_index],
None
);
/* map the parent window */
XMapWindow(d, frames[frames_index]);
frames_index++;
return True;
}