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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
/*
Copyright (C) 2003-2006 Fons Adriaensen <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "clxclient.h"
void X_hints::position (int x, int y)
{
_sh.flags |= PPosition;
_sh.x = x;
_sh.y = y;
}
void X_hints::size (int x, int y)
{
_sh.flags |= PSize;
_sh.width = x;
_sh.height = y;
}
void X_hints::minsize (int x, int y)
{
_sh.flags |= PMinSize;
_sh.min_width = x;
_sh.min_height = y;
}
void X_hints::maxsize (int x, int y)
{
_sh.flags |= PMaxSize;
_sh.max_width = x;
_sh.max_height = y;
}
void X_hints::sizeinc (int x, int y)
{
_sh.flags |= PResizeInc;
_sh.width_inc = x;
_sh.height_inc = y;
}
void X_hints::input (int input)
{
_mh.flags |= InputHint;
_mh.input = input;
}
void X_hints::state (int state)
{
_mh.flags |= StateHint;
_mh.initial_state = state;
}
void X_hints::group (Window group)
{
_mh.flags |= WindowGroupHint;
_mh.window_group = group;
}
X_window::X_window (X_display *disp) :
_ebits (0), _disp (disp), _pwin (0), _next (0), _list (0)
{
_wind = DefaultRootWindow (disp->_dpy);
}
X_window::X_window (X_window *pwin, int xpos, int ypos, int xsize, int ysize,
unsigned long bgcol, unsigned long bdcol, int bdpix) :
_ebits (0), _disp (pwin->_disp), _pwin (pwin), _next (pwin->_list), _list (0)
{
_pwin->_list = this;
_wind = XCreateSimpleWindow (_disp->_dpy, pwin->_wind,
xpos, ypos, xsize, ysize,
bdpix, bdcol, bgcol);
}
X_window::~X_window (void)
{
X_window *T;
if (_pwin)
{
T = _pwin->_list;
if (T == this) _pwin->_list = _next;
else
{
while (T && T->_next != this) T = T->_next;
if (T) T->_next = _next;
}
if (_wind)
{
XDestroyWindow (_disp->_dpy, _wind);
XFlush (dpy ());
}
}
while (_list)
{
if (_pwin) _list->_wind = 0;
delete _list;
}
}
X_window *X_window::find (Window w)
{
X_window *T, *W;
if (_wind == w) return this;
for (T = _list, W = 0; T && ! (W = T->find (w)); T = T->_next);
return W;
}
int X_window::x_resize (int xs, int ys) const
{
return XResizeWindow (_disp->_dpy, _wind, xs, ys);
}
int X_window::x_move (int xp, int yp) const
{
return XMoveWindow (_disp->_dpy, _wind, xp, yp);
}
int X_window::x_moveresize (int xp, int yp, int xs, int ys) const
{
return XMoveResizeWindow (_disp->_dpy, _wind, xp, yp, xs, ys);
}
int X_window::x_set_attrib (unsigned long mask, XSetWindowAttributes *attr) const
{
return XChangeWindowAttributes (_disp->_dpy, _wind, mask, attr);
}
int X_window::x_set_win_gravity (int gravity) const
{
XSetWindowAttributes attr;
attr.win_gravity = gravity;
return XChangeWindowAttributes (_disp->_dpy, _wind, CWWinGravity, &attr);
}
int X_window::x_set_bit_gravity (int gravity) const
{
XSetWindowAttributes attr;
attr.bit_gravity = gravity;
return XChangeWindowAttributes (_disp->_dpy, _wind, CWBitGravity, &attr);
}
int X_window::x_add_events (unsigned long events)
{
_ebits |= events;
return XSelectInput (_disp->_dpy, _wind, _ebits);
}
int X_window::x_rem_events (unsigned long events)
{
_ebits &= ~events;
return XSelectInput (_disp->_dpy, _wind, _ebits);
}
int X_window::x_set_title (const char *title)
{
return XStoreName (_disp->_dpy, _wind, title);
}
int X_window::x_set_background (unsigned long color)
{
return XSetWindowBackground (_disp->_dpy, _wind, color);
}
void X_window::x_apply (X_hints *hints)
{
if (hints->_sh.flags) XSetWMNormalHints (_disp->_dpy, _wind, &(hints->_sh));
if (hints->_mh.flags) XSetWMHints (_disp->_dpy, _wind, &(hints->_mh));
XSetClassHint (_disp->_dpy, _wind, &(hints->_ch));
hints->_sh.flags = 0;
hints->_mh.flags = 0;
}
X_rootwin::X_rootwin (X_display *disp) :
X_window (disp)
{
_disp->_xft = XftDrawCreate (dpy (), win (), dvi (), dcm ());
}
X_rootwin::~X_rootwin (void)
{
}
void X_rootwin::handle_event (void)
{
XEvent E;
while ( XCheckMaskEvent (_disp->_dpy, ~0L, &E)
|| XCheckTypedEvent (_disp->_dpy, SelectionNotify, &E)
|| XCheckTypedEvent (_disp->_dpy, ClientMessage, &E))
{
handle_event (&E);
}
}
void X_rootwin::handle_event (XEvent *E)
{
X_window *W;
W = find (((XAnyEvent *) E)->window);
if (W && W != this) W->handle_event (E);
XFlush (_disp->_dpy);
}
|