2 * swindow.c - simple window handling functions
4 * Copyright © 2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "common/swindow.h"
24 #include "common/util.h"
26 /** Create a simple window
27 * \param disp Display ref
28 * \param phys_screen physical screen id
29 * \param x x coordinate
30 * \param y y coordinate
33 * \param border_width window's border width
34 * \return pointer to a SimpleWindow
37 simplewindow_new(Display
*disp
, int phys_screen
, int x
, int y
,
38 unsigned int w
, unsigned int h
,
39 unsigned int border_width
)
41 XSetWindowAttributes wa
;
44 sw
= p_new(SimpleWindow
, 1);
48 sw
->geometry
.width
= w
;
49 sw
->geometry
.height
= h
;
52 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
53 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
54 wa
.override_redirect
= 1;
55 wa
.background_pixmap
= ParentRelative
;
56 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
57 sw
->window
= XCreateWindow(disp
,
58 RootWindow(disp
, phys_screen
),
61 DefaultDepth(disp
, phys_screen
),
63 DefaultVisual(disp
, phys_screen
),
64 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
,
67 sw
->drawable
= XCreatePixmap(disp
,
68 RootWindow(disp
, phys_screen
),
70 DefaultDepth(disp
, phys_screen
));
74 /** Destroy a simple window and all its resources
75 * \param sw the SimpleWindow to delete
78 simplewindow_delete(SimpleWindow
*sw
)
80 XDestroyWindow(sw
->display
, sw
->window
);
81 XFreePixmap(sw
->display
, sw
->drawable
);
85 /** Move a simple window
86 * \param sw the SimpleWindow to move
87 * \param x x coordinate
88 * \param y y coordinate
92 simplewindow_move(SimpleWindow
*sw
, int x
, int y
)
96 return XMoveWindow(sw
->display
, sw
->window
, x
, y
);
99 /** Refresh the window content
100 * \param sw the SimpleWindow to refresh
101 * \param phys_screen physical screen id
105 simplewindow_refresh_drawable(SimpleWindow
*sw
, int phys_screen
)
107 return XCopyArea(sw
->display
, sw
->drawable
,
109 DefaultGC(sw
->display
, phys_screen
), 0, 0,
115 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80