windowbox.c revision 0bbfda8a
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 21name_list **addWindowBox(char *boxname, char *geometry) 22{ 23 WindowBox *winbox; 24 25#if 0 26 printf("addWindowBox : name = %s, geometry = %s\n", boxname, geometry); 27#endif 28 winbox = malloc(sizeof(WindowBox)); 29 winbox->next = NULL; 30 winbox->name = strdup(boxname); 31 winbox->geometry = strdup(geometry); 32 winbox->winlist = NULL; 33 if(!Scr->FirstWindowBox) { 34 Scr->FirstWindowBox = winbox; 35 } 36 return (&(winbox->winlist)); 37} 38 39void createWindowBoxes(void) 40{ 41 WindowBox *winbox; 42 char title [128]; 43 XWMHints wmhints; 44 XSizeHints sizehints; 45 46 for(winbox = Scr->FirstWindowBox; winbox; winbox = winbox->next) { 47 int mask, x, y, gravity; 48 unsigned int w, h; 49 Window win; 50 51 mask = XParseGeometry(winbox->geometry, &x, &y, &w, &h); 52 if(mask & XNegative) { 53 x += Scr->rootw - w; 54 gravity = (mask & YNegative) ? SouthEastGravity : NorthEastGravity; 55 } 56 else { 57 gravity = (mask & YNegative) ? SouthWestGravity : NorthWestGravity; 58 } 59 if(mask & YNegative) { 60 y += Scr->rooth - h; 61 } 62 63 win = XCreateSimpleWindow(dpy, Scr->Root, x, y, w, h, 0, Scr->Black, 64 Scr->White); 65#if 0 66 printf("createWindowBoxes : name = %s, win = 0x%x, x = %d, y = %d, w = %d, h = %d\n", 67 winbox->name, win, x, y, w, h); 68#endif 69 sprintf(title, "%s", winbox->name); 70 71 sizehints.flags = USPosition | USSize | PWinGravity; 72 sizehints.x = x; 73 sizehints.y = y; 74 sizehints.width = w; 75 sizehints.height = h; 76 sizehints.win_gravity = gravity; 77 78 wmhints.initial_state = NormalState; 79 wmhints.input = True; 80 wmhints.flags = InputHint | StateHint; 81 82 XmbSetWMProperties(dpy, win, title, title, NULL, 0, 83 &sizehints, &wmhints, NULL); 84 85 winbox->window = win; 86 winbox->twmwin = AddWindow(win, AWT_WINDOWBOX, NULL, Scr->currentvs); 87 if(!winbox->twmwin) { 88 fprintf(stderr, "cannot create %s window box, exiting...\n", winbox->name); 89 exit(1); 90 } 91 winbox->twmwin->iswinbox = true; 92 XMapWindow(dpy, win); 93 } 94} 95 96WindowBox *findWindowBox(TwmWindow *twmwin) 97{ 98 WindowBox *winbox; 99 if(twmwin->iswinbox) { 100 return NULL; 101 } 102 if(!Scr->FirstWindowBox) { 103 return NULL; 104 } 105 for(winbox = Scr->FirstWindowBox; winbox; winbox = winbox->next) { 106 if(LookInList(winbox->winlist, twmwin->name, &twmwin->class)) { 107 if(visible(winbox->twmwin)) { 108 twmwin->winbox = winbox; 109 return winbox; 110 } 111 } 112 } 113 return NULL; 114} 115 116void ConstrainedToWinBox(TwmWindow *twmwin, int x, int y, int *nx, int *ny) 117{ 118 XWindowAttributes attr; 119 120 *nx = x; 121 *ny = y; 122 XGetWindowAttributes(dpy, twmwin->winbox->window, &attr); 123 if(x < 0) { 124 *nx = 0; 125 } 126 if(y < 0) { 127 *ny = 0; 128 } 129 if(x > attr.width - 1) { 130 *nx = attr.width - 1; 131 } 132 if(y > attr.height - 1) { 133 *ny = attr.height - 1; 134 } 135} 136 137void fittocontent(TwmWindow *twmwin) 138{ 139 TwmWindow *t; 140 int minx, miny, maxx, maxy, x, y, w, h; 141 minx = Scr->rootw; 142 miny = Scr->rooth; 143 maxx = 0; 144 maxy = 0; 145 for(t = Scr->FirstWindow; t != NULL; t = t->next) { 146 if(t->winbox && (t->winbox->twmwin == twmwin)) { 147 if(t->frame_x < minx) { 148 minx = t->frame_x; 149 } 150 if(t->frame_y < miny) { 151 miny = t->frame_y; 152 } 153 w = t->frame_width + 2 * t->frame_bw; 154 h = t->frame_height + 2 * t->frame_bw; 155 if(t->frame_x + w > maxx) { 156 maxx = t->frame_x + w; 157 } 158 if(t->frame_y + h > maxy) { 159 maxy = t->frame_y + h; 160 } 161 } 162 } 163 x = twmwin->frame_x + minx; 164 y = twmwin->frame_y + miny; 165 w = maxx - minx + 2 * twmwin->frame_bw3D; 166 h = maxy - miny + 2 * twmwin->frame_bw3D; 167 SetupWindow(twmwin, x, y, w, h, -1); 168 for(t = Scr->FirstWindow; t != NULL; t = t->next) { 169 if(t->winbox && (t->winbox->twmwin == twmwin)) { 170 SetupWindow(t, t->frame_x - minx, t->frame_y - miny, 171 t->frame_width, t->frame_height, -1); 172 } 173 } 174} 175