windowbox.c revision 645f5050
1/* 2 * [ ctwm ] 3 * 4 * Copyright 1992 Claude Lecommandeur. 5 * 6 * Permission to use, copy, modify and distribute this software [ctwm] and 7 * its documentation for any purpose is hereby granted without fee, provided 8 * that the above copyright notice appear in all copies and that both that 9 * copyright notice and this permission notice appear in supporting documen- 10 * tation, and that the name of Claude Lecommandeur not be used in adverti- 11 * sing or publicity pertaining to distribution of the software without 12 * specific, written prior permission. Claude Lecommandeur make no represen- 13 * tations about the suitability of this software for any purpose. It is 14 * provided "as is" without express or implied warranty. 15 * 16 * Claude Lecommandeur DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO 18 * EVENT SHALL Claude Lecommandeur BE LIABLE FOR ANY SPECIAL, INDIRECT OR 19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 20 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 21 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 22 * PERFORMANCE OF THIS SOFTWARE. 23 * 24 * Author: Claude Lecommandeur [ lecom@sic.epfl.ch ][ April 1992 ] 25 */ 26 27 28#include <stdio.h> 29#include "twm.h" 30#ifdef VMS 31#include <decw$include/Xatom.h> 32#else 33#include <X11/Xatom.h> 34#endif 35#include "screen.h" 36#include "add_window.h" 37#include "resize.h" 38#include "windowbox.h" 39 40name_list **addWindowBox (char *boxname, char *geometry) 41{ 42 WindowBox *winbox; 43 44#if 0 45 printf ("addWindowBox : name = %s, geometry = %s\n", boxname, geometry); 46#endif 47 winbox = (WindowBox*) malloc (sizeof (WindowBox)); 48 winbox->next = NULL; 49 winbox->name = strdup (boxname); 50 winbox->geometry = strdup (geometry); 51 winbox->winlist = NULL; 52 if (!Scr->FirstWindowBox) Scr->FirstWindowBox = winbox; 53 return (&(winbox->winlist)); 54} 55 56void createWindowBoxes (void) 57{ 58 WindowBox *winbox; 59 char title [128]; 60 XWMHints wmhints; 61 XSizeHints sizehints; 62 63 for (winbox = Scr->FirstWindowBox; winbox; winbox = winbox->next) { 64 int mask, x, y, gravity; 65 unsigned int w, h; 66 Window win; 67 68 mask = XParseGeometry (winbox->geometry, &x, &y, &w, &h); 69 if (mask & XNegative) { 70 x += Scr->rootw - w; 71 gravity = (mask & YNegative) ? SouthEastGravity : NorthEastGravity; 72 } else { 73 gravity = (mask & YNegative) ? SouthWestGravity : NorthWestGravity; 74 } 75 if (mask & YNegative) y += Scr->rooth - h; 76 77 win = XCreateSimpleWindow (dpy, Scr->Root, x, y, w, h, 0, Scr->Black, Scr->White); 78 /*printf ("createWindowBoxes : name = %s, win = 0x%x, x = %d, y = %d, w = %d, h = %d\n", 79 winbox->name, win, x, y, w, h); */ 80 sprintf (title, "%s", winbox->name); 81 XSetStandardProperties (dpy, win, title, title, None, NULL, 0, NULL); 82 sizehints.flags = USPosition | USSize | PWinGravity; 83 sizehints.x = x; 84 sizehints.y = y; 85 sizehints.width = w; 86 sizehints.height = h; 87 sizehints.win_gravity = gravity; 88 XSetWMSizeHints (dpy, win, &sizehints, XA_WM_NORMAL_HINTS); 89 90 wmhints.initial_state = NormalState; 91 wmhints.input = True; 92 wmhints.flags = InputHint | StateHint; 93 XSetWMHints (dpy, win, &wmhints); 94 95 winbox->window = win; 96 winbox->twmwin = AddWindow (win, 2, NULL); 97 if (!winbox->twmwin) { 98 fprintf (stderr, "cannot create %s window box, exiting...\n", winbox->name); 99 exit (1); 100 } 101 winbox->twmwin->iswinbox = TRUE; 102 XMapWindow (dpy, win); 103 } 104} 105 106WindowBox *findWindowBox (TwmWindow *twmwin) 107{ 108 WindowBox *winbox; 109 if (twmwin->iswinbox) return ((WindowBox*)0); 110 if (!Scr->FirstWindowBox) return ((WindowBox*)0); 111 for (winbox = Scr->FirstWindowBox; winbox; winbox = winbox->next) { 112 if (LookInList (winbox->winlist, twmwin->full_name, &twmwin->class)) { 113 if (visible (winbox->twmwin)) { 114 twmwin->winbox = winbox; 115 return (winbox); 116 } 117 } 118 } 119 return ((WindowBox*)0); 120} 121 122void ConstrainedToWinBox (TwmWindow *twmwin, int x, int y, int *nx, int *ny) 123{ 124 XWindowAttributes attr; 125 126 *nx = x; *ny = y; 127 XGetWindowAttributes (dpy, twmwin->winbox->window, &attr); 128 if (x < 0) *nx = 0; 129 if (y < 0) *ny = 0; 130 if (x > attr.width - 1) *nx = attr.width - 1; 131 if (y > attr.height - 1) *ny = attr.height - 1; 132} 133 134void fittocontent (TwmWindow *twmwin) 135{ 136 TwmWindow *t; 137 int minx, miny, maxx, maxy, x, y, w, h; 138 minx = Scr->rootw; 139 miny = Scr->rooth; 140 maxx = 0; 141 maxy = 0; 142 for (t = Scr->FirstWindow; t != NULL; t = t->next) { 143 if (t->winbox && (t->winbox->twmwin == twmwin)) { 144 if (t->frame_x < minx) minx = t->frame_x; 145 if (t->frame_y < miny) miny = t->frame_y; 146 w = t->frame_width + 2 * t->frame_bw; 147 h = t->frame_height + 2 * t->frame_bw; 148 if (t->frame_x + w > maxx) maxx = t->frame_x + w; 149 if (t->frame_y + h > maxy) maxy = t->frame_y + h; 150 } 151 } 152 x = twmwin->frame_x + minx; 153 y = twmwin->frame_y + miny; 154 w = maxx - minx + 2 * twmwin->frame_bw3D; 155 h = maxy - miny + 2 * twmwin->frame_bw3D; 156 SetupWindow (twmwin, x, y, w, h, -1); 157 for (t = Scr->FirstWindow; t != NULL; t = t->next) { 158 if (t->winbox && (t->winbox->twmwin == twmwin)) { 159 SetupWindow (t, t->frame_x - minx, t->frame_y - miny, 160 t->frame_width, t->frame_height, -1); 161 } 162 } 163} 164