CTWM
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
22name_list **addWindowBox(char *boxname, char *geometry)
23{
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
41{
43 char title [128];
44 XWMHints wmhints;
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;
57 }
58 else {
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
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
99{
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
118void ConstrainedToWinBox(TwmWindow *twmwin, int x, int y, int *nx, int *ny)
119{
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
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}
static int PlaceX
Definition add_window.c:82
TwmWindow * AddWindow(Window w, AWType wtype, IconMgr *iconp, VirtualScreen *vs)
Definition add_window.c:113
@ AWT_WINDOWBOX
Definition add_window.h:26
Display * dpy
Definition ctwm_main.c:84
#define Scr
int frame_x
X position on screen of frame.
void * LookInList(name_list *list_head, const char *name, XClassHint *class)
Definition list.c:101
int y
Definition menus.c:70
int x
Definition menus.c:69
Info and control for every X Window we take over.
struct WindowBox WindowBox
Definition types.h:44
void SetupWindow(TwmWindow *tmp_win, int x, int y, int w, int h, int bw)
bool visible(const TwmWindow *tmp_win)
Definition win_utils.c:341
void createWindowBoxes(void)
Definition windowbox.c:40
WindowBox * findWindowBox(TwmWindow *twmwin)
Definition windowbox.c:98
void fittocontent(TwmWindow *twmwin)
Definition windowbox.c:139
name_list ** addWindowBox(char *boxname, char *geometry)
Definition windowbox.c:22
void ConstrainedToWinBox(TwmWindow *twmwin, int x, int y, int *nx, int *ny)
Definition windowbox.c:118
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.