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 <xcb/xcb_aux.h>
25 #include "common/swindow.h"
26 #include "common/util.h"
28 /** Create a simple window
29 * \param conn Connection ref
30 * \param phys_screen physical screen id
31 * \param x x coordinate
32 * \param y y coordinate
35 * \param border_width window's border width
36 * \return pointer to a SimpleWindow
39 simplewindow_new(xcb_connection_t
*conn
, int phys_screen
, int x
, int y
,
40 unsigned int w
, unsigned int h
,
41 unsigned int border_width
)
44 xcb_screen_t
*s
= xcb_aux_get_screen(conn
, phys_screen
);
45 uint32_t create_win_val
[3];
47 sw
= p_new(SimpleWindow
, 1);
51 sw
->geometry
.width
= w
;
52 sw
->geometry
.height
= h
;
53 sw
->connection
= conn
;
54 sw
->phys_screen
= phys_screen
;
56 create_win_val
[0] = XCB_BACK_PIXMAP_PARENT_RELATIVE
;
57 create_win_val
[1] = 1;
58 create_win_val
[2] = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
|
59 XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY
| XCB_EVENT_MASK_ENTER_WINDOW
|
60 XCB_EVENT_MASK_LEAVE_WINDOW
| XCB_EVENT_MASK_STRUCTURE_NOTIFY
|
61 XCB_EVENT_MASK_BUTTON_PRESS
| XCB_EVENT_MASK_EXPOSURE
;
63 sw
->window
= xcb_generate_id(conn
);
64 xcb_create_window(conn
, s
->root_depth
, sw
->window
,
65 xutil_root_window(conn
, phys_screen
),
66 x
, y
, w
, h
, border_width
,
69 XCB_CW_BACK_PIXMAP
| XCB_CW_OVERRIDE_REDIRECT
| XCB_CW_EVENT_MASK
,
72 sw
->drawable
= xcb_generate_id(conn
);
73 xcb_create_pixmap(conn
, s
->root_depth
, sw
->drawable
,
74 xutil_root_window(conn
, phys_screen
), w
, h
);
79 /** Destroy a simple window and all its resources
80 * \param sw the SimpleWindow to delete
83 simplewindow_delete(SimpleWindow
**sw
)
85 xcb_destroy_window((*sw
)->connection
, (*sw
)->window
);
86 xcb_free_pixmap((*sw
)->connection
, (*sw
)->drawable
);
90 /** Move a simple window
91 * \param sw the SimpleWindow to move
92 * \param x x coordinate
93 * \param y y coordinate
96 simplewindow_move(SimpleWindow
*sw
, int x
, int y
)
98 const uint32_t move_win_vals
[] = { x
, y
};
102 xcb_configure_window(sw
->connection
, sw
->window
,
103 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
107 /** Resize a simple window
108 * \param sw the SimpleWindow to resize
110 * \param h new height
113 simplewindow_resize(SimpleWindow
*sw
, unsigned int w
, unsigned int h
)
115 xcb_screen_t
*s
= xcb_aux_get_screen(sw
->connection
, sw
->phys_screen
);
116 const uint32_t resize_win_vals
[] = { w
, h
};
118 sw
->geometry
.width
= w
;
119 sw
->geometry
.height
= h
;
120 xcb_free_pixmap(sw
->connection
, sw
->drawable
);
121 sw
->drawable
= xcb_generate_id(sw
->connection
);
122 xcb_create_pixmap(sw
->connection
, s
->root_depth
, sw
->drawable
,
123 xutil_root_window(sw
->connection
, sw
->phys_screen
), w
, h
);
124 xcb_configure_window(sw
->connection
, sw
->window
,
125 XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
129 /** Refresh the window content
130 * \param sw the SimpleWindow to refresh
131 * \param phys_screen physical screen id
134 simplewindow_refresh_drawable(SimpleWindow
*sw
, int phys_screen
)
136 xcb_screen_t
*s
= xcb_aux_get_screen(sw
->connection
, phys_screen
);
138 /* The default GC is just a newly created associated to the root
140 xcb_drawable_t gc_draw
= s
->root
;
141 xcb_gcontext_t gc
= xcb_generate_id(sw
->connection
);
143 const uint32_t gc_mask
= XCB_GC_FOREGROUND
| XCB_GC_BACKGROUND
;
144 const uint32_t gc_values
[2] = { s
->black_pixel
, s
->white_pixel
};
146 xcb_create_gc(sw
->connection
, gc
, gc_draw
, gc_mask
, gc_values
);
147 xcb_copy_area(sw
->connection
, sw
->drawable
,
148 sw
->window
, gc
, 0, 0, 0, 0,
150 sw
->geometry
.height
);
153 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80