mirror of
https://git.yoctoproject.org/libmatchboxwm2
synced 2025-11-19 06:25:42 +08:00
This removes mb-wm-main-context.c since we now just use a glib mainloop context instead. The new mainloop integration API allows matchbox to be fed X events from an external toolkit so core matchbox no longer needs to have any gtk specific event source integration code, since it should be straightforward for a gtk based wm/compositor to decide to take ownership of event fetching and pass those events through to matchbox manually if they want. In the process of removing references to the mb-wm-main-context API it was necessary to refactor how we handle mouse grabs for moving and resizing windows. Previously we would do an X grab and then then immediately enter a tight loop, polling for X mouse events and handling them until something triggers an ungrab and then resume fetching events in the normal way. Now though when we do the mouse grab we just use mb_wm_manager_add_event_handler to register a temporary interest in mouse events and mb_wm_manager_remove_event_handler when the grab is finished. This means we can continue to use the normal event delivery mechanism during a grab and more importantly we don't block the mainloop which would really upset window managers and compositors needing to process other asynchronous events during a grab.
148 lines
3.2 KiB
C
148 lines
3.2 KiB
C
#include "mb-wm-comp-mgr-clutter.h"
|
|
#include <clutter/x11/clutter-x11.h>
|
|
|
|
#include <matchbox/matchbox.h>
|
|
#include <signal.h>
|
|
|
|
enum {
|
|
KEY_ACTION_PAGE_NEXT,
|
|
KEY_ACTION_PAGE_PREV,
|
|
KEY_ACTION_TOGGLE_FULLSCREEN,
|
|
KEY_ACTION_TOGGLE_DESKTOP,
|
|
};
|
|
|
|
static MBWMManager *wm = NULL;
|
|
|
|
#if MBWM_WANT_DEBUG
|
|
/*
|
|
* The Idea behind this is quite simple: when all managed windows are closed
|
|
* and the WM exits, there should have been an unref call for each ref call. To
|
|
* test do something like
|
|
*
|
|
* export DISPLAY=:whatever;
|
|
* export MB_DEBUG=obj-ref,obj-unref
|
|
* matchbox-window-manager-2-simple &
|
|
* gedit
|
|
* kill -TERM $(pidof gedit)
|
|
* kill -TERM $(pidof matchbox-window-manager-2-simple)
|
|
*
|
|
* If you see '=== object count at exit x ===' then we either have a leak
|
|
* (x > 0) or are unrefing a dangling pointer (x < 0).
|
|
*/
|
|
static void
|
|
signal_handler (int sig)
|
|
{
|
|
if (sig == SIGTERM)
|
|
{
|
|
int count;
|
|
|
|
mb_wm_object_unref (MB_WM_OBJECT (wm));
|
|
mb_wm_object_dump ();
|
|
|
|
exit (sig);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
void
|
|
key_binding_func (MBWMManager *wm,
|
|
MBWMKeyBinding *binding,
|
|
void *userdata)
|
|
{
|
|
printf(" ### got key press ### \n");
|
|
int action;
|
|
|
|
action = (int)(userdata);
|
|
|
|
switch (action)
|
|
{
|
|
case KEY_ACTION_PAGE_NEXT:
|
|
mb_wm_manager_cycle_apps (wm, False);
|
|
break;
|
|
case KEY_ACTION_PAGE_PREV:
|
|
mb_wm_manager_cycle_apps (wm, True);
|
|
break;
|
|
case KEY_ACTION_TOGGLE_FULLSCREEN:
|
|
printf(" ### KEY_ACTION_TOGGLE_FULLSCREEN ### \n");
|
|
break;
|
|
case KEY_ACTION_TOGGLE_DESKTOP:
|
|
printf(" ### KEY_ACTION_TOGGLE_DESKTOP ### \n");
|
|
mb_wm_manager_toggle_desktop (wm);
|
|
break;
|
|
}
|
|
}
|
|
|
|
ClutterX11FilterReturn
|
|
forward_xevent (XEvent *xevent,
|
|
ClutterEvent *event,
|
|
void *user_data)
|
|
{
|
|
mb_wm_manager_handle_xlib_event (wm, xevent);
|
|
return CLUTTER_X11_FILTER_CONTINUE;
|
|
}
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
Display * dpy = NULL;
|
|
MBWMCompMgr *compositor;
|
|
|
|
#if MBWM_WANT_DEBUG
|
|
struct sigaction sa;
|
|
sigfillset(&sa.sa_mask);
|
|
sa.sa_handler = signal_handler;
|
|
sigaction(SIGTERM, &sa, NULL);
|
|
#endif
|
|
|
|
mb_wm_object_init();
|
|
|
|
/* We share Clutter's display connection, and hook our xevent
|
|
* handler into the clutter main loop.
|
|
*/
|
|
if (dpy)
|
|
clutter_x11_set_display (dpy);
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
if (!dpy)
|
|
dpy = clutter_x11_get_default_display ();
|
|
|
|
clutter_x11_add_filter (forward_xevent, wm);
|
|
|
|
wm = mb_wm_manager_new_with_dpy (argc, argv, dpy);
|
|
compositor = mb_wm_comp_mgr_clutter_new (wm);
|
|
mb_wm_manager_start_with_compositor (wm, compositor);
|
|
mb_wm_object_unref (MB_WM_OBJECT (compositor));
|
|
|
|
if (wm == NULL)
|
|
mb_wm_util_fatal_error("OOM?");
|
|
|
|
mb_wm_keys_binding_add_with_spec (wm,
|
|
"<alt>d",
|
|
key_binding_func,
|
|
NULL,
|
|
(void*)KEY_ACTION_TOGGLE_DESKTOP);
|
|
|
|
mb_wm_keys_binding_add_with_spec (wm,
|
|
"<alt>n",
|
|
key_binding_func,
|
|
NULL,
|
|
(void*)KEY_ACTION_PAGE_NEXT);
|
|
|
|
mb_wm_keys_binding_add_with_spec (wm,
|
|
"<alt>p",
|
|
key_binding_func,
|
|
NULL,
|
|
(void*)KEY_ACTION_PAGE_PREV);
|
|
|
|
clutter_main ();
|
|
|
|
mb_wm_object_unref (MB_WM_OBJECT (wm));
|
|
|
|
#if MBWM_WANT_DEBUG
|
|
mb_wm_object_dump ();
|
|
#endif
|
|
|
|
return 1;
|
|
}
|