diff options
-rw-r--r-- | src/display.c | 78 | ||||
-rw-r--r-- | src/screen.c | 13 | ||||
-rw-r--r-- | src/screen.h | 2 | ||||
-rw-r--r-- | src/stack.c | 179 | ||||
-rw-r--r-- | src/util.c | 30 | ||||
-rw-r--r-- | src/util.h | 3 | ||||
-rw-r--r-- | src/window.c | 30 |
7 files changed, 246 insertions, 89 deletions
diff --git a/src/display.c b/src/display.c index 09c853a7..1d56840a 100644 --- a/src/display.c +++ b/src/display.c @@ -185,6 +185,11 @@ meta_display_open (const char *name) display->atom_net_wm_state_modal = atoms[27]; display->atom_net_client_list = atoms[28]; display->atom_net_client_list_stacking = atoms[29]; + + /* Offscreen unmapped window used for _NET_SUPPORTING_WM_CHECK, + * created in screen_new + */ + display->leader_window = None; screens = NULL; i = 0; @@ -225,13 +230,6 @@ meta_display_open (const char *name) display->last_button_num = 0; display->is_double_click = FALSE; - /* Offscreen unmapped window used for _NET_SUPPORTING_WM_CHECK - */ - display->leader_window = - XCreateSimpleWindow (display->xdisplay, - ((MetaScreen*)display->screens->data)->xroot, - -100, -100, 1, 1, 0, 0, 0); - set_string_hint (display, display->leader_window, display->atom_net_supporting_wm_check, @@ -303,7 +301,8 @@ meta_display_close (MetaDisplay *display) */ g_hash_table_destroy (display->window_ids); - XDestroyWindow (display->xdisplay, display->leader_window); + if (display->leader_window != None) + XDestroyWindow (display->xdisplay, display->leader_window); meta_event_queue_free (display->events); XCloseDisplay (display->xdisplay); @@ -720,7 +719,62 @@ event_get_modified_window (MetaDisplay *display, return None; } } - + +static const char* +focus_detail (int d) +{ + const char *detail = "(????)"; + switch (d) + { + case NotifyAncestor: + detail = "NotifyAncestor"; + break; + case NotifyDetailNone: + detail = "NotifyDetailNone"; + break; + case NotifyInferior: + detail = "NotifyInferior"; + break; + case NotifyNonlinear: + detail = "NotifyNonlinear"; + break; + case NotifyNonlinearVirtual: + detail = "NotifyNonlinearVirtual"; + break; + case NotifyPointer: + detail = "NotifyPointer"; + break; + case NotifyPointerRoot: + detail = "NotifyPointerRoot"; + break; + case NotifyVirtual: + detail = "NotifyVirtual"; + break; + } + + return detail; +} + +static const char* +focus_mode (int m) +{ + const char *mode = "(????)"; + switch (m) + { + case NotifyNormal: + mode = "NotifyNormal"; + break; + case NotifyGrab: + mode = "NotifyGrab"; + break; + case NotifyUngrab: + mode = "NotifyUngrab"; + break; + } + + return mode; +} + static void meta_spew_event (MetaDisplay *display, XEvent *event) @@ -773,9 +827,15 @@ meta_spew_event (MetaDisplay *display, break; case FocusIn: name = "FocusIn"; + extra = g_strdup_printf ("detail: %s mode: %s\n", + focus_detail (event->xfocus.detail), + focus_mode (event->xfocus.mode)); break; case FocusOut: name = "FocusOut"; + extra = g_strdup_printf ("detail: %s mode: %s\n", + focus_detail (event->xfocus.detail), + focus_mode (event->xfocus.mode)); break; case KeymapNotify: name = "KeymapNotify"; diff --git a/src/screen.c b/src/screen.c index 09e00ff6..a13f9a3e 100644 --- a/src/screen.c +++ b/src/screen.c @@ -47,6 +47,8 @@ set_wm_check_hint (MetaScreen *screen) { unsigned long data[1]; + g_return_val_if_fail (screen->display->leader_window != None, 0); + data[0] = screen->display->leader_window; XChangeProperty (screen->display->xdisplay, screen->xroot, @@ -59,9 +61,9 @@ set_wm_check_hint (MetaScreen *screen) static int set_supported_hint (MetaScreen *screen) { -#define N_SUPPORTED 17 +#define N_SUPPORTED 19 Atom atoms[N_SUPPORTED]; - + atoms[0] = screen->display->atom_net_wm_name; atoms[1] = screen->display->atom_net_close_window; atoms[2] = screen->display->atom_net_wm_state; @@ -79,6 +81,8 @@ set_supported_hint (MetaScreen *screen) atoms[14] = screen->display->atom_net_wm_window_type_dialog; atoms[15] = screen->display->atom_net_wm_window_type_normal; atoms[16] = screen->display->atom_net_wm_state_modal; + atoms[17] = screen->display->atom_net_client_list; + atoms[18] = screen->display->atom_net_client_list_stacking; XChangeProperty (screen->display->xdisplay, screen->xroot, screen->display->atom_net_wm_supported, @@ -153,6 +157,11 @@ meta_screen_new (MetaDisplay *display, screen->showing_tooltip = FALSE; + if (display->leader_window == None) + display->leader_window = XCreateSimpleWindow (display->xdisplay, + screen->xroot, + -100, -100, 1, 1, 0, 0, 0); + set_supported_hint (screen); set_wm_check_hint (screen); diff --git a/src/screen.h b/src/screen.h index 89c71302..24337492 100644 --- a/src/screen.h +++ b/src/screen.h @@ -55,6 +55,8 @@ struct _MetaScreen * root window) */ PangoContext *pango_context; + + MetaStack *stack; }; MetaScreen* meta_screen_new (MetaDisplay *display, diff --git a/src/stack.c b/src/stack.c index 4999095d..2cd76b45 100644 --- a/src/stack.c +++ b/src/stack.c @@ -22,6 +22,7 @@ #include "stack.h" #include "window.h" #include "errors.h" +#include "frame.h" #include <X11/Xatom.h> @@ -166,6 +167,7 @@ meta_stack_remove (MetaStack *stack, op->add_order = -1; /* Need to immediately remove from layer lists */ + g_assert (g_list_find (stack->layers[window->layer], window) != NULL); stack->layers[window->layer] = g_list_remove (stack->layers[window->layer], window); @@ -206,6 +208,7 @@ meta_stack_raise (MetaStack *stack, op = ensure_op (stack, window); op->raised = TRUE; op->lowered = FALSE; + op->update_transient = TRUE; meta_stack_sync_to_server (stack); } @@ -219,6 +222,7 @@ meta_stack_lower (MetaStack *stack, op = ensure_op (stack, window); op->raised = FALSE; op->lowered = TRUE; + op->update_transient = TRUE; meta_stack_sync_to_server (stack); } @@ -261,51 +265,91 @@ compute_layer (MetaWindow *window) window->desc, window->layer); } -static gboolean -is_transient_for (MetaWindow *transient, - MetaWindow *parent) +static GList* +ensure_before (GList *list, + gconstpointer before, + gconstpointer value) { - MetaWindow *w; + /* ensure before is before value */ + GList *b_link; + GList *v_link; + GList *tmp; - w = transient; - while (w != NULL) + b_link = NULL; + v_link = NULL; + tmp = list; + while (tmp != NULL) { - if (w->xtransient_for == None) - return FALSE; - - w = meta_display_lookup_x_window (w->display, w->xtransient_for); + if (tmp->data == before) + { + if (v_link == NULL) + return list; /* already before */ - if (w == transient) - return FALSE; /* Cycle detected */ - else if (w == parent) - return TRUE; + b_link = tmp; + } + else if (tmp->data == value) + { + v_link = tmp; + } + + tmp = tmp->next; + } + + /* We weren't already before if we got here */ + list = g_list_remove_link (list, b_link); + + if (v_link == list) + { + b_link->next = v_link; + v_link->prev = b_link; + list = b_link; + } + else + { + b_link->prev = v_link->prev; + b_link->prev->next = b_link; + b_link->next = v_link; + v_link->prev = b_link; } - return FALSE; + return list; } -static int -window_stack_cmp (MetaWindow *a, - MetaWindow *b) +static GList* +sort_window_list (GList *list) { - /* Less than means higher in stacking, i.e. at the - * front of the list. + GList *tmp; + GList *copy; + + /* This algorithm could stand to be a bit less + * quadratic */ - - if (a->xtransient_for != None && - is_transient_for (a, b)) - { - /* a is higher than b due to transient_for */ - return -1; - } - else if (b->xtransient_for != None && - is_transient_for (b, a)) + copy = g_list_copy (list); + tmp = copy; + while (tmp != NULL) { - /* b is higher than a due to transient_for */ - return 1; + MetaWindow *w = tmp->data; + + if (w->xtransient_for != None) + { + MetaWindow *parent; + + parent = + meta_display_lookup_x_window (w->display, w->xtransient_for); + + if (parent) + { + meta_verbose ("Stacking %s above %s due to transiency\n", + w->desc, parent->desc); + list = ensure_before (list, w, parent); + } + } + + tmp = tmp->next; } - else - return 0; /* leave things as-is */ + g_list_free (copy); + + return list; } static void @@ -321,6 +365,7 @@ meta_stack_sync_to_server (MetaStack *stack) int i, j; int old_size; GArray *stacked; + GArray *root_children_stacked; /* Bail out if frozen */ if (stack->freeze_count > 0) @@ -445,6 +490,14 @@ meta_stack_sync_to_server (MetaStack *stack) old_layer = op->window->layer; + if (op->add_order >= 0) + { + /* need to add to a layer */ + stack->layers[op->window->layer] = + g_list_prepend (stack->layers[op->window->layer], + op->window); + } + if (op->update_layer) { compute_layer (op->window); @@ -486,6 +539,8 @@ meta_stack_sync_to_server (MetaStack *stack) stack->layers[op->window->layer] = g_list_prepend (stack->layers[op->window->layer], op->window); + + needs_sort[op->window->layer] = TRUE; } else if (op->lowered) { @@ -496,44 +551,38 @@ meta_stack_sync_to_server (MetaStack *stack) stack->layers[op->window->layer] = g_list_append (stack->layers[op->window->layer], op->window); + + needs_sort[op->window->layer] = TRUE; } } + if (op->window) + op->window->stack_op = NULL; g_free (op); tmp = tmp->next; - } + } g_list_free (stack->pending); stack->pending = NULL; stack->n_added = 0; - /* Sort the layer lists */ - i = 0; - while (i < META_LAYER_LAST) - { - if (needs_sort[i]) - { - stack->layers[i] = - g_list_sort (stack->layers[i], - (GCompareFunc) window_stack_cmp); - } - - ++i; - } - - /* Create stacked xwindow array */ + /* Create stacked xwindow arrays */ stacked = g_array_new (FALSE, FALSE, sizeof (Window)); - i = 0; + root_children_stacked = g_array_new (FALSE, FALSE, sizeof (Window)); + i = 0; while (i < META_LAYER_LAST) - { + { + /* Sort each layer... */ if (needs_sort[i]) { - stack->layers[i] = - g_list_sort (stack->layers[i], - (GCompareFunc) window_stack_cmp); + meta_verbose ("Sorting layer %d\n", i); + stack->layers[i] = sort_window_list (stack->layers[i]); } + /* ... then append it */ + meta_verbose ("Layer %d: ", i); + meta_push_no_msg_prefix (); tmp = stack->layers[i]; while (tmp != NULL) { @@ -541,8 +590,18 @@ meta_stack_sync_to_server (MetaStack *stack) g_array_append_val (stacked, w->xwindow); + if (w->frame) + g_array_append_val (root_children_stacked, w->frame->xwindow); + else + g_array_append_val (root_children_stacked, w->xwindow); + + meta_verbose ("%s ", w->desc); + tmp = tmp->next; } + + meta_verbose ("\n"); + meta_pop_no_msg_prefix (); ++i; } @@ -554,10 +613,13 @@ meta_stack_sync_to_server (MetaStack *stack) /* Sync to server */ + meta_verbose ("Restacking %d windows\n", + root_children_stacked->len); + meta_error_trap_push (stack->screen->display); XRestackWindows (stack->screen->display->xdisplay, - (Window *) stacked->data, - stacked->len); + (Window *) root_children_stacked->data, + root_children_stacked->len); meta_error_trap_pop (stack->screen->display); /* on error, a window was destroyed; it should eventually * get removed from the stacking list when we unmanage it @@ -569,19 +631,20 @@ meta_stack_sync_to_server (MetaStack *stack) XChangeProperty (stack->screen->display->xdisplay, stack->screen->xroot, stack->screen->display->atom_net_client_list, - XA_ATOM, + XA_WINDOW, 32, PropModeReplace, stack->windows->data, stack->windows->len); XChangeProperty (stack->screen->display->xdisplay, stack->screen->xroot, stack->screen->display->atom_net_client_list_stacking, - XA_ATOM, + XA_WINDOW, 32, PropModeReplace, stacked->data, stacked->len); g_array_free (stacked, TRUE); + g_array_free (root_children_stacked, TRUE); /* That was scary... */ } @@ -29,6 +29,7 @@ static gboolean is_verbose = FALSE; static gboolean is_debugging = FALSE; static gboolean is_syncing = FALSE; +static int no_prefix = 0; gboolean meta_is_verbose (void) @@ -95,7 +96,8 @@ meta_debug_spew (const char *format, ...) str = g_strdup_vprintf (format, args); va_end (args); - fputs ("Window manager: ", stderr); + if (no_prefix == 0) + fputs ("Window manager: ", stderr); fputs (str, stderr); g_free (str); @@ -116,7 +118,8 @@ meta_verbose (const char *format, ...) str = g_strdup_vprintf (format, args); va_end (args); - fputs ("Window manager: ", stderr); + if (no_prefix == 0) + fputs ("Window manager: ", stderr); fputs (str, stderr); g_free (str); @@ -134,7 +137,8 @@ meta_bug (const char *format, ...) str = g_strdup_vprintf (format, args); va_end (args); - fputs ("Bug in window manager: ", stderr); + if (no_prefix == 0) + fputs ("Bug in window manager: ", stderr); fputs (str, stderr); g_free (str); @@ -155,7 +159,8 @@ meta_warning (const char *format, ...) str = g_strdup_vprintf (format, args); va_end (args); - fputs ("Window manager: ", stderr); + if (no_prefix == 0) + fputs ("Window manager: ", stderr); fputs (str, stderr); g_free (str); @@ -173,10 +178,25 @@ meta_fatal (const char *format, ...) str = g_strdup_vprintf (format, args); va_end (args); - fputs ("Window manager: ", stderr); + if (no_prefix == 0) + fputs ("Window manager: ", stderr); fputs (str, stderr); g_free (str); meta_exit (META_EXIT_ERROR); } + +void +meta_push_no_msg_prefix (void) +{ + ++no_prefix; +} + +void +meta_pop_no_msg_prefix (void) +{ + g_return_if_fail (no_prefix > 0); + + --no_prefix; +} @@ -53,6 +53,9 @@ void meta_warning (const char *format, void meta_fatal (const char *format, ...) G_GNUC_PRINTF (1, 2); +void meta_push_no_msg_prefix (void); +void meta_pop_no_msg_prefix (void); + /* FIXME */ #include <config.h> #define _(x) x diff --git a/src/window.c b/src/window.c index a4249be2..809bce75 100644 --- a/src/window.c +++ b/src/window.c @@ -780,25 +780,25 @@ meta_window_focus (MetaWindow *window, { meta_verbose ("Setting input focus to window %s, input: %d take_focus: %d\n", window->desc, window->input, window->take_focus); + + meta_error_trap_push (window->display); if (window->input) { - meta_error_trap_push (window->display); - if (window->take_focus) - { - meta_window_send_icccm_message (window, - window->display->atom_wm_take_focus, - timestamp); - } - else - { - XSetInputFocus (window->display->xdisplay, - window->xwindow, - RevertToParent, - timestamp); - } - meta_error_trap_pop (window->display); + XSetInputFocus (window->display->xdisplay, + window->xwindow, + RevertToPointerRoot, + timestamp); + } + + if (window->take_focus) + { + meta_window_send_icccm_message (window, + window->display->atom_wm_take_focus, + timestamp); } + + meta_error_trap_pop (window->display); } void |