CTWM
Toggle main menu visibility
Loading...
Searching...
No Matches
/usr/src/RPM/BUILD/ctwm-4.1.0/windowbox.c
Go to the documentation of this file.
1
/*
2
* Copyright 1992 Claude Lecommandeur.
3
*/
4
5
6
#include "
ctwm.h
"
7
8
#include <stdio.h>
9
#include <stdlib.h>
10
11
#include <X11/Xatom.h>
12
13
#include "
screen.h
"
14
#include "
add_window.h
"
15
#include "
list.h
"
16
#include "
windowbox.h
"
17
#include "
win_decorations.h
"
18
#include "
win_resize.h
"
19
#include "
win_utils.h
"
20
#include "
xparsegeometry.h
"
21
22
name_list
**
addWindowBox
(
char
*boxname,
char
*geometry)
23
{
24
WindowBox
*winbox;
25
26
#if 0
27
printf(
"addWindowBox : name = %s, geometry = %s\n"
, boxname, geometry);
28
#endif
29
winbox = malloc(
sizeof
(
WindowBox
));
30
winbox->next = NULL;
31
winbox->name = strdup(boxname);
32
winbox->geometry = strdup(geometry);
33
winbox->winlist = NULL;
34
if
(!
Scr
->FirstWindowBox) {
35
Scr
->FirstWindowBox = winbox;
36
}
37
return
(&(winbox->winlist));
38
}
39
40
void
createWindowBoxes
(
void
)
41
{
42
WindowBox
*winbox;
43
char
title [128];
44
XWMHints wmhints;
45
XSizeHints sizehints;
46
47
for
(winbox =
Scr
->FirstWindowBox; winbox; winbox = winbox->next) {
48
int
mask, x, y, gravity;
49
unsigned
int
w, h;
50
Window win;
51
52
mask =
RLayoutXParseGeometry
(
Scr
->Layout, winbox->geometry,
53
&x, &y, &w, &h);
54
if
(mask & XNegative) {
55
x +=
Scr
->rootw - w;
56
gravity = (mask & YNegative) ? SouthEastGravity : NorthEastGravity;
57
}
58
else
{
59
gravity = (mask & YNegative) ? SouthWestGravity : NorthWestGravity;
60
}
61
if
(mask & YNegative) {
62
y +=
Scr
->rooth - h;
63
}
64
65
win = XCreateSimpleWindow(
dpy
,
Scr
->Root, x, y, w, h, 0,
Scr
->Black,
66
Scr
->White);
67
#if 0
68
printf(
"createWindowBoxes : name = %s, win = 0x%x, x = %d, y = %d, w = %d, h = %d\n"
,
69
winbox->name, win, x, y, w, h);
70
#endif
71
sprintf(title,
"%s"
, winbox->name);
72
73
sizehints.flags = USPosition | USSize | PWinGravity;
74
sizehints.x = x;
75
sizehints.y = y;
76
sizehints.width = w;
77
sizehints.height = h;
78
sizehints.win_gravity = gravity;
79
80
wmhints.initial_state = NormalState;
81
wmhints.input = True;
82
wmhints.flags = InputHint | StateHint;
83
84
XmbSetWMProperties(
dpy
, win, title, title, NULL, 0,
85
&sizehints, &wmhints, NULL);
86
87
winbox->window = win;
88
winbox->twmwin =
AddWindow
(win,
AWT_WINDOWBOX
, NULL,
Scr
->currentvs);
89
if
(!winbox->twmwin) {
90
fprintf(stderr,
"cannot create %s window box, exiting...\n"
, winbox->name);
91
exit(1);
92
}
93
winbox->twmwin->iswinbox =
true
;
94
XMapWindow(
dpy
, win);
95
}
96
}
97
98
WindowBox
*
findWindowBox
(
TwmWindow
*twmwin)
99
{
100
WindowBox
*winbox;
101
if
(twmwin->iswinbox) {
102
return
NULL;
103
}
104
if
(!
Scr
->FirstWindowBox) {
105
return
NULL;
106
}
107
for
(winbox =
Scr
->FirstWindowBox; winbox; winbox = winbox->next) {
108
if
(
LookInList
(winbox->winlist, twmwin->
name
, &twmwin->
class
)) {
109
if
(
visible
(winbox->twmwin)) {
110
twmwin->winbox = winbox;
111
return
winbox;
112
}
113
}
114
}
115
return
NULL;
116
}
117
118
void
ConstrainedToWinBox
(
TwmWindow
*twmwin,
int
x,
int
y,
int
*nx,
int
*ny)
119
{
120
XWindowAttributes attr;
121
122
*nx = x;
123
*ny = y;
124
XGetWindowAttributes(
dpy
, twmwin->winbox->window, &attr);
125
if
(x < 0) {
126
*nx = 0;
127
}
128
if
(y < 0) {
129
*ny = 0;
130
}
131
if
(x > attr.width - 1) {
132
*nx = attr.width - 1;
133
}
134
if
(y > attr.height - 1) {
135
*ny = attr.height - 1;
136
}
137
}
138
139
void
fittocontent
(
TwmWindow
*twmwin)
140
{
141
TwmWindow
*t;
142
int
minx, miny, maxx, maxy, x, y, w, h;
143
minx =
Scr
->rootw;
144
miny =
Scr
->rooth;
145
maxx = 0;
146
maxy = 0;
147
for
(t =
Scr
->FirstWindow; t != NULL; t = t->
next
) {
148
if
(t->winbox && (t->winbox->twmwin == twmwin)) {
149
if
(t->
frame_x
< minx) {
150
minx = t->
frame_x
;
151
}
152
if
(t->
frame_y
< miny) {
153
miny = t->
frame_y
;
154
}
155
w = t->
frame_width
+ 2 * t->
frame_bw
;
156
h = t->
frame_height
+ 2 * t->
frame_bw
;
157
if
(t->
frame_x
+ w > maxx) {
158
maxx = t->
frame_x
+ w;
159
}
160
if
(t->
frame_y
+ h > maxy) {
161
maxy = t->
frame_y
+ h;
162
}
163
}
164
}
165
x = twmwin->
frame_x
+ minx;
166
y = twmwin->
frame_y
+ miny;
167
w = maxx - minx + 2 * twmwin->
frame_bw3D
;
168
h = maxy - miny + 2 * twmwin->
frame_bw3D
;
169
SetupWindow
(twmwin, x, y, w, h, -1);
170
for
(t =
Scr
->FirstWindow; t != NULL; t = t->
next
) {
171
if
(t->winbox && (t->winbox->twmwin == twmwin)) {
172
SetupWindow
(t, t->
frame_x
- minx, t->
frame_y
- miny,
173
t->
frame_width
, t->
frame_height
, -1);
174
}
175
}
176
}
AddWindow
TwmWindow * AddWindow(Window w, AWType wtype, IconMgr *iconp, VirtualScreen *vs)
Definition
add_window.c:113
add_window.h
AWT_WINDOWBOX
@ AWT_WINDOWBOX
Definition
add_window.h:26
ctwm.h
dpy
Display * dpy
Definition
ctwm_main.c:84
Scr
#define Scr
TwmWindow::frame_x
int frame_x
X position on screen of frame.
Definition
twm_window_struct.h:80
TwmWindow::frame_y
int frame_y
Y position on screen of frame.
Definition
twm_window_struct.h:81
TwmWindow::frame_bw
int frame_bw
2d border width.
Definition
twm_window_struct.h:86
TwmWindow::frame_width
unsigned int frame_width
Width of frame.
Definition
twm_window_struct.h:82
TwmWindow::frame_height
unsigned int frame_height
Height of frame.
Definition
twm_window_struct.h:83
TwmWindow::frame_bw3D
int frame_bw3D
3d border width.
Definition
twm_window_struct.h:88
LookInList
void * LookInList(name_list *list_head, const char *name, XClassHint *class)
Definition
list.c:101
list.h
screen.h
TwmWindow
Info and control for every X Window we take over.
Definition
twm_window_struct.h:34
TwmWindow::next
struct TwmWindow * next
Next TwmWindow on the Screen.
Definition
twm_window_struct.h:35
TwmWindow::name
char * name
Current window name. Points into TwmWindow::names.
Definition
twm_window_struct.h:107
TwmWindow::class
XClassHint class
Window class info. From XGetClassHint().
Definition
twm_window_struct.h:158
name_list
Definition
list.h:20
WindowBox
struct WindowBox WindowBox
Definition
types.h:44
SetupWindow
void SetupWindow(TwmWindow *tmp_win, int x, int y, int w, int h, int bw)
Definition
win_decorations.c:71
win_decorations.h
win_resize.h
visible
bool visible(const TwmWindow *tmp_win)
Definition
win_utils.c:341
win_utils.h
createWindowBoxes
void createWindowBoxes(void)
Definition
windowbox.c:40
findWindowBox
WindowBox * findWindowBox(TwmWindow *twmwin)
Definition
windowbox.c:98
fittocontent
void fittocontent(TwmWindow *twmwin)
Definition
windowbox.c:139
addWindowBox
name_list ** addWindowBox(char *boxname, char *geometry)
Definition
windowbox.c:22
ConstrainedToWinBox
void ConstrainedToWinBox(TwmWindow *twmwin, int x, int y, int *nx, int *ny)
Definition
windowbox.c:118
windowbox.h
RLayoutXParseGeometry
int RLayoutXParseGeometry(RLayout *layout, const char *geometry, int *x, int *y, unsigned int *width, unsigned int *height)
Parse an X Geometry out to get the positions and sizes.
Definition
xparsegeometry.c:25
xparsegeometry.h
windowbox.c
Generated by
1.18.0