summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJess VanDerwalker <washu@sonic.net>2012-07-31 13:11:49 -0700
committerJess VanDerwalker <washu@sonic.net>2012-08-29 09:14:43 -0700
commita7500cc39177ee595c67cc1fa4fc29375562ff78 (patch)
treef7dc7ecf6309e8de8becf888273e928d5c22a4c6
parent402cb8e4cd43052a7649a182ca7bae1490b1cd43 (diff)
libxcwm: atoms.c created for ICCCM functions.
Created an atoms.c file to hold functions that deal with initializing and getting and setting data from ICCCM atoms. Moved functions from window.c and init.c that handle ICCCM atoms into this file. atoms.c added to Makefile.am Removed global xcwm_wm_atoms_t _wm_atoms variable and placed in xcwm_context_t as xcwm_context_t *atoms. Updated references so they now point to context->atoms. Allocation memory for struct in context initalization and freeing in xcwm_context_close(). Signed-off-by: Jess VanDerwalker <washu@sonic.net> Reviewed-by: Jeremy Huddlestone Seqouia <jeremyhu@apple.com>
-rw-r--r--include/xcwm/context.h7
-rw-r--r--src/libxcwm/Makefile.am3
-rw-r--r--src/libxcwm/atoms.c188
-rw-r--r--src/libxcwm/context.c6
-rw-r--r--src/libxcwm/event_loop.c4
-rw-r--r--src/libxcwm/init.c42
-rw-r--r--src/libxcwm/window.c106
-rw-r--r--src/libxcwm/xcwm_internal.h49
8 files changed, 238 insertions, 167 deletions
diff --git a/include/xcwm/context.h b/include/xcwm/context.h
index 664d478..2385875 100644
--- a/include/xcwm/context.h
+++ b/include/xcwm/context.h
@@ -38,11 +38,18 @@
struct xcwm_window_t;
typedef struct xcwm_window_t xcwm_window_t;
+/**
+ * Struct to hold ICCCM/EWMH data for context.
+ */
+struct xcwm_wm_atoms_t;
+typedef struct xcwm_wm_atoms_t xcwm_wm_atoms_t;
+
/* Structure to hold connection data */
struct xcwm_context_t {
xcb_connection_t *conn;
xcwm_window_t *root_window;
int damage_event_mask;
+ xcwm_wm_atoms_t *atoms;
};
typedef struct xcwm_context_t xcwm_context_t;
diff --git a/src/libxcwm/Makefile.am b/src/libxcwm/Makefile.am
index af665ff..134945c 100644
--- a/src/libxcwm/Makefile.am
+++ b/src/libxcwm/Makefile.am
@@ -15,4 +15,5 @@ libxcwm_la_SOURCES = \
init.c \
util.c \
image.c \
- input.c
+ input.c \
+ atoms.c
diff --git a/src/libxcwm/atoms.c b/src/libxcwm/atoms.c
new file mode 100644
index 0000000..76c78ef
--- /dev/null
+++ b/src/libxcwm/atoms.c
@@ -0,0 +1,188 @@
+/* Copyright (c) 2013 Jess VanDerwalker <jvanderw@freedesktop.org>
+ *
+ * atom.c
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <xcb/xcb.h>
+#include <xcb/xcb_atom.h>
+#include <xcb/xcb_icccm.h>
+#include <xcb/xcb_ewmh.h>
+#include <xcwm/xcwm.h>
+#include "xcwm_internal.h"
+
+/* Local functions */
+
+/* Get and set the size hints for the window */
+void
+set_window_size_hints(xcwm_window_t *window);
+
+
+void
+_xcwm_atoms_init(xcwm_context_t *context)
+{
+ xcb_intern_atom_reply_t *atom_reply;
+ xcb_intern_atom_cookie_t atom_cookie;
+
+ /* WM_PROTOCOLS */
+ atom_cookie = xcb_intern_atom(context->conn,
+ 0,
+ strlen("WM_PROTOCOLS"),
+ "WM_PROTOCOLS");
+ atom_reply = xcb_intern_atom_reply(context->conn,
+ atom_cookie,
+ NULL);
+ if (!atom_reply) {
+ context->atoms->wm_protocols_atom = 0;
+ }
+ else {
+ context->atoms->wm_protocols_atom = atom_reply->atom;
+ free(atom_reply);
+ }
+
+ /* WM_DELETE_WINDOW atom */
+ atom_cookie = xcb_intern_atom(context->conn,
+ 0,
+ strlen("WM_DELETE_WINDOW"),
+ "WM_DELETE_WINDOW");
+ atom_reply = xcb_intern_atom_reply(context->conn,
+ atom_cookie,
+ NULL);
+ if (!atom_reply) {
+ context->atoms->wm_delete_window_atom = 0;
+ }
+ else {
+ context->atoms->wm_delete_window_atom = atom_reply->atom;
+ free(atom_reply);
+ }
+
+}
+
+void
+_xcwm_atoms_init_window(xcwm_window_t *window)
+{
+ xcb_get_property_cookie_t cookie;
+ xcb_window_t transient;
+ xcb_generic_error_t *error;
+ uint8_t success;
+
+ _xcwm_atoms_set_window_name(window);
+ _xcwm_atoms_set_wm_delete(window);
+ set_window_size_hints(window);
+
+ /* Get the window this one is transient for */
+ cookie = xcb_icccm_get_wm_transient_for(window->context->conn,
+ window->window_id);
+ success = xcb_icccm_get_wm_transient_for_reply(window->context->conn,
+ cookie,
+ &transient,
+ &error);
+ if (success) {
+ window->transient_for = _xcwm_get_window_node_by_window_id(transient);
+ /* FIXME: Currently we assume that any window that is
+ * transient for another is a dialog. */
+ window->type = XCWM_WINDOW_TYPE_DIALOG;
+ } else {
+ window->transient_for = NULL;
+ window->type = XCWM_WINDOW_TYPE_NORMAL;
+ }
+}
+
+
+void
+_xcwm_atoms_set_window_name(xcwm_window_t *window)
+{
+ xcb_get_property_cookie_t cookie;
+ xcb_icccm_get_text_property_reply_t reply;
+ xcb_generic_error_t *error;
+
+ cookie = xcb_icccm_get_wm_name(window->context->conn, window->window_id);
+ if (!xcb_icccm_get_wm_name_reply(window->context->conn,
+ cookie, &reply, &error)) {
+ window->name = malloc(sizeof(char));
+ window->name[0] = '\0';
+ return;
+ }
+
+ window->name = malloc(sizeof(char) * (reply.name_len + 1));
+ strncpy(window->name, reply.name, reply.name_len);
+ window->name[reply.name_len] = '\0';
+ xcb_icccm_get_text_property_reply_wipe(&reply);
+}
+
+
+void
+_xcwm_atoms_set_wm_delete(xcwm_window_t *window)
+{
+ xcb_get_property_cookie_t cookie;
+ xcb_icccm_get_wm_protocols_reply_t reply;
+ xcb_generic_error_t *error;
+ int i;
+
+ /* Get the WM_PROTOCOLS */
+ cookie = xcb_icccm_get_wm_protocols(window->context->conn,
+ window->window_id,
+ window->context->atoms->wm_protocols_atom);
+
+ if (xcb_icccm_get_wm_protocols_reply(window->context->conn,
+ cookie, &reply, &error) == 1) {
+ /* See if the WM_DELETE_WINDOW is set in WM_PROTOCOLS */
+ for (i = 0; i < reply.atoms_len; i++) {
+ if (reply.atoms[i] == window->context->atoms->wm_delete_window_atom) {
+ window->wm_delete_set = 1;
+ break;
+ }
+ }
+ } else {
+ window->wm_delete_set = 0;
+ return;
+ }
+ xcb_icccm_get_wm_protocols_reply_wipe(&reply);
+
+ return;
+}
+
+void
+set_window_size_hints(xcwm_window_t *window)
+{
+ xcb_get_property_cookie_t cookie;
+ xcb_size_hints_t hints;
+
+ cookie = xcb_icccm_get_wm_normal_hints(window->context->conn,
+ window->window_id);
+ if (!xcb_icccm_get_wm_normal_hints_reply(window->context->conn,
+ cookie, &hints, NULL)) {
+ /* Use 0 for all values (as set in calloc), or previous values */
+ return;
+ }
+ window->sizing->min_width = hints.min_width;
+ window->sizing->min_height = hints.min_height;;
+ window->sizing->max_width = hints.max_width;
+ window->sizing->max_height = hints.max_height;
+ window->sizing->width_inc = hints.width_inc;
+ window->sizing->height_inc = hints.height_inc;
+}
diff --git a/src/libxcwm/context.c b/src/libxcwm/context.c
index 3dc978c..05a09c2 100644
--- a/src/libxcwm/context.c
+++ b/src/libxcwm/context.c
@@ -92,6 +92,8 @@ xcwm_context_open(char *display)
root_context->root_window->dmg_bounds = malloc(sizeof(xcwm_rect_t));
assert(root_context->root_window->bounds);
assert(root_context->root_window->dmg_bounds);
+ root_context->atoms = malloc(sizeof(xcwm_wm_atoms_t));
+ assert(root_context->atoms);
root_context->conn = conn;
root_context->root_window->parent = 0;
@@ -118,7 +120,7 @@ xcwm_context_open(char *display)
_xcwm_init_extension(conn, "XTEST");
_xcwm_init_extension(conn, "XKEYBOARD");
- _xcwm_get_wm_atoms(root_context);
+ _xcwm_atoms_init(root_context);
return root_context;
}
@@ -139,6 +141,8 @@ xcwm_context_close(xcwm_context_t *context)
head = _xcwm_window_list_head;
}
+ free(context->atoms);
+
// Terminate the event loop
if (_xcwm_event_stop_loop() != 1) {
printf("Event loop failed to close\n");
diff --git a/src/libxcwm/event_loop.c b/src/libxcwm/event_loop.c
index 24efd90..8bc1bb7 100644
--- a/src/libxcwm/event_loop.c
+++ b/src/libxcwm/event_loop.c
@@ -366,8 +366,8 @@ run_event_loop(void *thread_arg_struct)
/* If this is WM_PROTOCOLS, do not send event, just
* handle internally */
- if (notify->atom == _wm_atoms->wm_protocols_atom) {
- _xcwm_window_set_wm_delete(event_conn, window);
+ if (notify->atom == window->context->atoms->wm_protocols_atom) {
+ _xcwm_atoms_set_wm_delete(window);
}
break;
}
diff --git a/src/libxcwm/init.c b/src/libxcwm/init.c
index 988efd4..fef6e51 100644
--- a/src/libxcwm/init.c
+++ b/src/libxcwm/init.c
@@ -36,7 +36,6 @@
#include "xcwm_internal.h"
-xcwm_wm_atoms *_wm_atoms = NULL;
xcb_query_extension_reply_t *
_xcwm_init_extension(xcb_connection_t *conn, char *extension_name)
@@ -128,44 +127,3 @@ _xcwm_init_xfixes(xcwm_context_t *contxt)
free(reply);
}
-void
-_xcwm_get_wm_atoms(xcwm_context_t *context)
-{
- xcb_intern_atom_reply_t *atom_reply;
- xcb_intern_atom_cookie_t atom_cookie;
-
- _wm_atoms = malloc(sizeof(xcwm_wm_atoms));
-
- /* WM_PROTOCOLS */
- atom_cookie = xcb_intern_atom(context->conn,
- 0,
- strlen("WM_PROTOCOLS"),
- "WM_PROTOCOLS");
- atom_reply = xcb_intern_atom_reply(context->conn,
- atom_cookie,
- NULL);
- if (!atom_reply) {
- _wm_atoms->wm_protocols_atom = 0;
- }
- else {
- _wm_atoms->wm_protocols_atom = atom_reply->atom;
- free(atom_reply);
- }
-
- /* WM_DELETE_WINDOW atom */
- atom_cookie = xcb_intern_atom(context->conn,
- 0,
- strlen("WM_DELETE_WINDOW"),
- "WM_DELETE_WINDOW");
- atom_reply = xcb_intern_atom_reply(context->conn,
- atom_cookie,
- NULL);
- if (!atom_reply) {
- _wm_atoms->wm_delete_window_atom = 0;
- }
- else {
- _wm_atoms->wm_delete_window_atom = atom_reply->atom;
- free(atom_reply);
- }
-
-}
diff --git a/src/libxcwm/window.c b/src/libxcwm/window.c
index 7877fb8..cfc12f9 100644
--- a/src/libxcwm/window.c
+++ b/src/libxcwm/window.c
@@ -29,18 +29,12 @@
#include <xcb/xfixes.h>
#include <xcb/damage.h>
-#include <xcb/xcb_icccm.h>
-#include <xcb/xcb_ewmh.h>
#include <xcwm/xcwm.h>
#include "xcwm_internal.h"
/* Functions only used within this file */
-/* Sets the WM_* properties we care about in context */
-void
-set_icccm_properties(xcb_connection_t *conn, xcwm_window_t *window);
-
/* Set the event masks on a window */
void
set_window_event_masks(xcb_connection_t *conn, xcwm_window_t *window);
@@ -157,7 +151,7 @@ _xcwm_window_create(xcwm_context_t *context, xcb_window_t new_window,
set_window_event_masks(context->conn, window);
/* Set the ICCCM properties we care about */
- set_icccm_properties(context->conn, window);
+ _xcwm_atoms_init_window(window);
/* register for damage */
init_damage_on_window(context->conn, window);
@@ -266,9 +260,9 @@ xcwm_window_request_close(xcwm_window_t *window)
event.response_type = XCB_CLIENT_MESSAGE;
event.window = window->window_id;
- event.type = _wm_atoms->wm_protocols_atom;
+ event.type = window->context->atoms->wm_protocols_atom;
event.format = 32;
- event.data.data32[0] = _wm_atoms->wm_delete_window_atom;
+ event.data.data32[0] = window->context->atoms->wm_delete_window_atom;
event.data.data32[1] = XCB_CURRENT_TIME;
xcb_send_event(window->context->conn, 0, window->window_id,
@@ -413,100 +407,6 @@ set_window_event_masks(xcb_connection_t *conn, xcwm_window_t *window)
XCB_CW_EVENT_MASK, values);
}
-void
-set_icccm_properties(xcb_connection_t *conn, xcwm_window_t *window)
-{
- xcb_get_property_cookie_t cookie;
- xcb_window_t transient;
- xcb_generic_error_t *error;
- uint8_t success;
-
- set_wm_name_in_context(conn, window);
- _xcwm_window_set_wm_delete(conn, window);
- set_wm_size_hints_for_window(conn, window);
-
- /* Get the window this one is transient for */
- cookie = xcb_icccm_get_wm_transient_for(conn, window->window_id);
- success = xcb_icccm_get_wm_transient_for_reply(conn, cookie,
- &transient, &error);
- if (success) {
- window->transient_for = _xcwm_get_window_node_by_window_id(transient);
- /* FIXME: Currently we assume that any window that is
- * transient for another is a dialog. */
- window->type = XCWM_WINDOW_TYPE_DIALOG;
- } else {
- window->transient_for = NULL;
- window->type = XCWM_WINDOW_TYPE_NORMAL;
- }
-}
-
-void
-set_wm_name_in_context(xcb_connection_t *conn, xcwm_window_t *window)
-{
- xcb_get_property_cookie_t cookie;
- xcb_icccm_get_text_property_reply_t reply;
- xcb_generic_error_t *error;
-
- cookie = xcb_icccm_get_wm_name(conn, window->window_id);
- if (!xcb_icccm_get_wm_name_reply(conn, cookie, &reply, &error)) {
- window->name = malloc(sizeof(char));
- window->name[0] = '\0';
- return;
- }
-
- window->name = malloc(sizeof(char) * (reply.name_len + 1));
- strncpy(window->name, reply.name, reply.name_len);
- window->name[reply.name_len] = '\0';
- xcb_icccm_get_text_property_reply_wipe(&reply);
-}
-
-void
-_xcwm_window_set_wm_delete(xcb_connection_t *conn, xcwm_window_t *window)
-{
- xcb_get_property_cookie_t cookie;
- xcb_icccm_get_wm_protocols_reply_t reply;
- xcb_generic_error_t *error;
- int i;
-
- /* Get the WM_PROTOCOLS */
- cookie = xcb_icccm_get_wm_protocols(conn, window->window_id,
- _wm_atoms->wm_protocols_atom);
-
- if (xcb_icccm_get_wm_protocols_reply(conn, cookie, &reply, &error) == 1) {
- /* See if the WM_DELETE_WINDOW is in WM_PROTOCOLS */
- for (i = 0; i < reply.atoms_len; i++) {
- if (reply.atoms[i] == _wm_atoms->wm_delete_window_atom) {
- window->wm_delete_set = 1;
- break;
- }
- }
- } else {
- window->wm_delete_set = 0;
- return;
- }
- xcb_icccm_get_wm_protocols_reply_wipe(&reply);
-
- return;
-}
-
-void
-set_wm_size_hints_for_window(xcb_connection_t *conn, xcwm_window_t *window)
-{
- xcb_get_property_cookie_t cookie;
- xcb_size_hints_t hints;
-
- cookie = xcb_icccm_get_wm_normal_hints(conn, window->window_id);
- if (!xcb_icccm_get_wm_normal_hints_reply(conn, cookie, &hints, NULL)) {
- /* Use 0 for all values (as set in calloc), or previous values */
- return;
- }
- window->sizing->min_width = hints.min_width;
- window->sizing->min_height = hints.min_height;;
- window->sizing->max_width = hints.max_width;
- window->sizing->max_height = hints.max_height;
- window->sizing->width_inc = hints.width_inc;
- window->sizing->height_inc = hints.height_inc;
-}
void
init_damage_on_window(xcb_connection_t *conn, xcwm_window_t *window)
diff --git a/src/libxcwm/xcwm_internal.h b/src/libxcwm/xcwm_internal.h
index b853d6f..1b6d414 100644
--- a/src/libxcwm/xcwm_internal.h
+++ b/src/libxcwm/xcwm_internal.h
@@ -49,11 +49,11 @@ typedef struct xcwm_event_connetion {
/**
* Structure to hold WM_* atoms that we care about
*/
-typedef struct xcwm_wm_atoms {
+struct xcwm_wm_atoms_t {
xcb_atom_t wm_protocols_atom;
xcb_atom_t wm_delete_window_atom;
xcb_atom_t wm_transient_for_atom;
-} xcwm_wm_atoms;
+};
/**
* Local data type for image data.
@@ -61,11 +61,6 @@ typedef struct xcwm_wm_atoms {
typedef struct image_data_t image_data_t;
/**
- * Global for the atoms needed
- */
-extern xcwm_wm_atoms *_wm_atoms;
-
-/**
* Mutex lock supplied to client to lock event loop thread
*/
extern pthread_mutex_t event_thread_lock;
@@ -169,13 +164,6 @@ _xcwm_init_composite(xcwm_context_t *contxt);
void
_xcwm_init_xfixes(xcwm_context_t *contxt);
-/**
- * Get the values for the WM_* atoms that we need.
- * @param contxt The context
- */
-void
-_xcwm_get_wm_atoms(xcwm_context_t *contxt);
-
/****************
* event_loop.c
****************/
@@ -287,13 +275,38 @@ _xcwm_resize_window(xcb_connection_t *conn, xcb_window_t window,
void
_xcwm_map_window(xcb_connection_t *conn, xcwm_window_t *window);
+
+/****************
+ * atoms.c
+ ****************/
+
/**
- * Set the WM_DELETE ICCCM protocol for the window.
- * @param conn The connection to xserver
- * @param window The window to set wm_delete_set flag on.
+ * Get the values for the WM_* atoms that we need.
+ * @param context The context
*/
void
-_xcwm_window_set_wm_delete(xcb_connection_t *conn, xcwm_window_t *window);
+_xcwm_atoms_init(xcwm_context_t *context);
+/**
+ * Get and set the initial values ICCCM/EWMH atoms for the given
+ * window.
+ * @param window The window to get and set atoms values for.
+ */
+void
+_xcwm_atoms_init_window(xcwm_window_t *window);
+
+/**
+ * Get and set the WM_NAME of the window.
+ * @param window The window
+ */
+void
+_xcwm_atoms_set_window_name(xcwm_window_t *window);
+
+/**
+ * Get the set the WM_DELETE_WINDOWatom for the winodw.
+ * @param window The window.
+ */
+void
+_xcwm_atoms_set_wm_delete(xcwm_window_t *window);
#endif /* _XTOQ_INTERNAL_H_ */