summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2012-11-08 23:57:19 +0000
committerJon TURNEY <jon.turney@dronecode.org.uk>2012-11-21 14:03:11 +0000
commite9e46e5241a56bc68a75841b9cc6f37a419b1b90 (patch)
tree6c4e71567b64c6ee96263d9a5843a796d7416b3d
parentbf40fc2bac82852bf2dffc9efdb4ed98c746b8c5 (diff)
2nd pass at generic window appearance interest framework
-rw-r--r--include/Makefile.am5
-rw-r--r--include/xcwm/atoms.h38
-rw-r--r--include/xcwm/xcwm.h1
-rw-r--r--src/libxcwm/atoms.c57
4 files changed, 78 insertions, 23 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 9014ed9..bcbc3ba 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -8,6 +8,5 @@ xcwminclude_HEADERS = \
xcwm/event.h \
xcwm/image.h \
xcwm/input.h \
- xcwm/keyboard.h
-
-
+ xcwm/keyboard.h \
+ xcwm/atoms.h
diff --git a/include/xcwm/atoms.h b/include/xcwm/atoms.h
new file mode 100644
index 0000000..f4db068
--- /dev/null
+++ b/include/xcwm/atoms.h
@@ -0,0 +1,38 @@
+/* Copyright (c) 2012 Jon TURNEY
+ *
+ * xcwm/atoms.h
+ *
+ * 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.
+ */
+
+#ifndef XCWM_ATOMS_H
+#define XCWM_ATOMS_H
+
+/**
+ * register interest in an atom
+ * @param context The context
+ * @param atom The name of the atom
+ * @param event The event to be delivered when atom changes
+ */
+xcb_atom_t
+xcwm_atom_register(xcwm_context_t *context, const char *atom, xcwm_event_type_t event);
+
+#endif /* XCWM_ATOMS_H */
diff --git a/include/xcwm/xcwm.h b/include/xcwm/xcwm.h
index fdba2e9..a667522 100644
--- a/include/xcwm/xcwm.h
+++ b/include/xcwm/xcwm.h
@@ -36,5 +36,6 @@
#include <xcwm/input.h>
#include <xcwm/image.h>
#include <xcwm/keyboard.h>
+#include <xcwm/atoms.h>
#endif /* _XCWM_XCWM_H_ */
diff --git a/src/libxcwm/atoms.c b/src/libxcwm/atoms.c
index 5a667e8..6033ce3 100644
--- a/src/libxcwm/atoms.c
+++ b/src/libxcwm/atoms.c
@@ -79,15 +79,8 @@ set_window_opacity(xcwm_window_t *window, xcwm_property_t *property);
static void
set_window_name(xcwm_window_t *window, xcwm_property_t *property);
-xcwm_property_t property_table[] =
- {
- { "_NET_WM_NAME", set_window_name, XCWM_EVENT_WINDOW_NAME },
- { "WM_NAME", set_window_name, XCWM_EVENT_WINDOW_NAME },
- { "_NET_WM_WINDOW_TYPE", setup_window_type, XCWM_EVENT_WINDOW_APPEARANCE },
- { "WM_NORMAL_HINTS", set_window_size_hints, 0 },
- { "_NET_WM_WINDOW_OPACITY", set_window_opacity, XCWM_EVENT_WINDOW_APPEARANCE },
- { NULL, NULL, 0 }
- };
+static xcwm_property_t *property_table = NULL;
+static unsigned int property_table_entries = 0;;
static xcb_atom_t
_xcwm_atom_get(xcwm_context_t *context, const char *atomName)
@@ -110,6 +103,28 @@ _xcwm_atom_get(xcwm_context_t *context, const char *atomName)
return atom;
}
+static xcwm_property_t *
+_xcwm_atom_register(xcwm_context_t *context, const char *name, xcwm_property_change_fn_t *prop_change_fn, xcwm_event_type_t event)
+{
+ // XXX: what if atom is already registered?
+ property_table_entries++;
+ property_table = realloc(property_table, property_table_entries * sizeof(struct xcwm_property_t));
+
+ xcwm_property_t *new_property = &(property_table[property_table_entries - 1]);
+ new_property->name = name;
+ new_property->prop_change_fn = prop_change_fn;
+ new_property->event = event;
+ new_property->atom = _xcwm_atom_get(context, name);
+
+ return new_property;
+}
+
+xcb_atom_t
+xcwm_atom_register(xcwm_context_t *context, const char *atom, xcwm_event_type_t event)
+{
+ return _xcwm_atom_register(context, atom, NULL, event)->atom;
+}
+
int
_xcwm_atoms_init(xcwm_context_t *context)
{
@@ -161,11 +176,11 @@ _xcwm_atoms_init(xcwm_context_t *context)
/* Get the ICCCM atoms we need that are not included in the
* xcb_ewmh_connection_t. */
- int i;
- for (i = 0; property_table[i].name != NULL; i++)
- {
- property_table[i].atom = _xcwm_atom_get(context, property_table[i].name);
- }
+ _xcwm_atom_register(context, "_NET_WM_NAME", set_window_name, XCWM_EVENT_WINDOW_NAME);
+ _xcwm_atom_register(context, "WM_NAME", set_window_name, XCWM_EVENT_WINDOW_NAME);
+ _xcwm_atom_register(context, "_NET_WM_WINDOW_TYPE", setup_window_type, XCWM_EVENT_WINDOW_APPEARANCE);
+ _xcwm_atom_register(context, "WM_NORMAL_HINTS", set_window_size_hints, 0);
+ _xcwm_atom_register(context, "_NET_WM_WINDOW_OPACITY", set_window_opacity, XCWM_EVENT_WINDOW_APPEARANCE);
/* WM_DELETE_WINDOW atom */
context->atoms->wm_delete_window_atom = _xcwm_atom_get(context, "WM_DELETE_WINDOW");
@@ -233,21 +248,23 @@ _xcwm_atoms_init_window(xcwm_window_t *window)
_xcwm_atoms_set_wm_delete(window);
/* Put the value of all properties we consider into effect */
- int i;
- for (i = 0; property_table[i].name != NULL; i++)
+ unsigned int i;
+ for (i = 0; i < property_table_entries; i++)
{
- (property_table[i].prop_change_fn)(window, &(property_table[i]));
+ if (property_table[i].prop_change_fn)
+ (property_table[i].prop_change_fn)(window, &(property_table[i]));
}
}
int
_xcwm_atom_change_to_event(xcb_atom_t atom, xcwm_window_t *window, xcwm_event_type_t *event)
{
- int i;
- for (i = 0; property_table[i].name != NULL; i++) {
+ unsigned int i;
+ for (i = 0; i < property_table_entries; i++) {
if (property_table[i].atom == atom) {
/* Take the value into consideration */
- (property_table[i].prop_change_fn)(window, &(property_table[i]));
+ if (property_table[i].prop_change_fn)
+ (property_table[i].prop_change_fn)(window, &(property_table[i]));
/* and translate to XCWM_ event */
*event = property_table[i].event;