awesome/common/swindow.c

156 lines
5.0 KiB
C
Raw Normal View History

2008-01-26 17:58:01 +01:00
/*
* swindow.c - simple window handling functions
*
* Copyright © 2008 Julien Danjou <julien@danjou.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
2008-03-21 16:50:17 +01:00
#include <xcb/xcb.h>
#include <xcb/xcb_aux.h>
2008-01-26 17:58:01 +01:00
#include "common/swindow.h"
#include "common/util.h"
/** Create a simple window
2008-03-21 16:50:17 +01:00
* \param conn Connection ref
* \param phys_screen physical screen id
* \param x x coordinate
* \param y y coordinate
* \param w width
* \param h height
* \param border_width window's border width
* \return pointer to a SimpleWindow
*/
2008-01-26 17:58:01 +01:00
SimpleWindow *
2008-03-21 16:50:17 +01:00
simplewindow_new(xcb_connection_t *conn, int phys_screen, int x, int y,
2008-01-26 17:58:01 +01:00
unsigned int w, unsigned int h,
unsigned int border_width)
{
SimpleWindow *sw;
2008-03-21 16:50:17 +01:00
xcb_screen_t *s = xcb_aux_get_screen(conn, phys_screen);
uint32_t create_win_val[3];
2008-01-26 17:58:01 +01:00
sw = p_new(SimpleWindow, 1);
sw->geometry.x = x;
sw->geometry.y = y;
sw->geometry.width = w;
sw->geometry.height = h;
2008-03-21 16:50:17 +01:00
sw->connection = conn;
sw->phys_screen = phys_screen;
2008-01-26 17:58:01 +01:00
2008-03-21 16:50:17 +01:00
create_win_val[0] = XCB_BACK_PIXMAP_PARENT_RELATIVE;
create_win_val[1] = 1;
create_win_val[2] = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_ENTER_WINDOW |
XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_STRUCTURE_NOTIFY |
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_EXPOSURE;
sw->window = xcb_generate_id(conn);
xcb_create_window(conn, s->root_depth, sw->window,
root_window(conn, phys_screen),
x, y, w, h, border_width,
XCB_COPY_FROM_PARENT,
s->root_visual,
XCB_CW_BACK_PIXMAP | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
create_win_val);
x_select_input(conn, sw->window, create_win_val[2]);
sw->drawable = xcb_generate_id(conn);
xcb_create_pixmap(conn, s->root_depth, sw->drawable,
root_window(conn, phys_screen), w, h);
2008-01-26 17:58:01 +01:00
return sw;
}
/** Destroy a simple window and all its resources
* \param sw the SimpleWindow to delete
*/
2008-01-26 17:58:01 +01:00
void
simplewindow_delete(SimpleWindow **sw)
2008-01-26 17:58:01 +01:00
{
2008-03-21 16:50:17 +01:00
xcb_destroy_window((*sw)->connection, (*sw)->window);
xcb_free_pixmap((*sw)->connection, (*sw)->drawable);
p_delete(sw);
2008-01-26 17:58:01 +01:00
}
/** Move a simple window
* \param sw the SimpleWindow to move
* \param x x coordinate
* \param y y coordinate
*/
2008-03-21 16:50:17 +01:00
void
2008-01-26 17:58:01 +01:00
simplewindow_move(SimpleWindow *sw, int x, int y)
{
2008-03-21 16:50:17 +01:00
const uint32_t move_win_vals[] = { x, y };
2008-01-26 17:58:01 +01:00
sw->geometry.x = x;
sw->geometry.y = y;
2008-03-21 16:50:17 +01:00
xcb_configure_window(sw->connection, sw->window,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
move_win_vals);
2008-01-26 17:58:01 +01:00
}
2008-03-14 12:54:35 +01:00
/** Resize a simple window
* \param sw the SimpleWindow to resize
* \param w new width
* \param h new height
*/
2008-03-21 16:50:17 +01:00
void
2008-03-14 12:54:35 +01:00
simplewindow_resize(SimpleWindow *sw, unsigned int w, unsigned int h)
{
2008-03-21 16:50:17 +01:00
xcb_screen_t *s = xcb_aux_get_screen(sw->connection, sw->phys_screen);
const uint32_t resize_win_vals[] = { w, h };
2008-03-14 12:54:35 +01:00
sw->geometry.width = w;
sw->geometry.height = h;
2008-03-21 16:50:17 +01:00
xcb_free_pixmap(sw->connection, sw->drawable);
sw->drawable = xcb_generate_id(sw->connection);
xcb_create_pixmap(sw->connection, s->root_depth, sw->drawable,
root_window(sw->connection, sw->phys_screen), w, h);
xcb_configure_window(sw->connection, sw->window,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
resize_win_vals);
2008-03-14 12:54:35 +01:00
}
/** Refresh the window content
* \param sw the SimpleWindow to refresh
* \param phys_screen physical screen id
*/
2008-03-21 16:50:17 +01:00
void
2008-01-26 17:58:01 +01:00
simplewindow_refresh_drawable(SimpleWindow *sw, int phys_screen)
{
2008-03-21 16:50:17 +01:00
xcb_screen_t *s = xcb_aux_get_screen(sw->connection, phys_screen);
/* The default GC is just a newly created associated to the root
* window */
xcb_drawable_t gc_draw = s->root;
xcb_gcontext_t gc = xcb_generate_id(sw->connection);
const uint32_t gc_mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND;
const uint32_t gc_values[2] = { s->black_pixel, s->white_pixel };
xcb_create_gc(sw->connection, gc, gc_draw, gc_mask, gc_values);
xcb_copy_area(sw->connection, sw->drawable,
sw->window, gc, 0, 0, 0, 0,
sw->geometry.width,
sw->geometry.height);
2008-01-26 17:58:01 +01:00
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80