diff --git a/panels/display/scrollarea.c b/panels/display/scrollarea.c index 3262e516d..e3ec36a9d 100644 --- a/panels/display/scrollarea.c +++ b/panels/display/scrollarea.c @@ -763,9 +763,6 @@ emit_input (FooScrollArea *scroll_area, if (!func) return; - if (type != FOO_MOTION) - emit_input (scroll_area, FOO_MOTION, x, y, func, data); - event.type = type; event.x = x; event.y = y; @@ -789,7 +786,6 @@ process_event (FooScrollArea *scroll_area, emit_input (scroll_area, input_type, x, y, scroll_area->priv->grab_func, scroll_area->priv->grab_data); - return; } #if 0 @@ -828,10 +824,20 @@ process_event (FooScrollArea *scroll_area, if (inside) { - emit_input (scroll_area, input_type, - x, y, - path->func, - path->data); + if (scroll_area->priv->grabbed) + { + emit_input (scroll_area, FOO_DRAG_HOVER, + x, y, + path->func, + path->data); + } + else + { + emit_input (scroll_area, input_type, + x, y, + path->func, + path->data); + } return; } @@ -1322,13 +1328,17 @@ foo_scroll_area_begin_grab (FooScrollArea *scroll_area, } void -foo_scroll_area_end_grab (FooScrollArea *scroll_area) +foo_scroll_area_end_grab (FooScrollArea *scroll_area, + FooScrollAreaEvent *event) { g_return_if_fail (FOO_IS_SCROLL_AREA (scroll_area)); scroll_area->priv->grabbed = FALSE; scroll_area->priv->grab_func = NULL; scroll_area->priv->grab_data = NULL; + + if (event != NULL) + process_event (scroll_area, FOO_DROP, event->x, event->y); } gboolean diff --git a/panels/display/scrollarea.h b/panels/display/scrollarea.h index b394c17bc..9d0fa0eca 100644 --- a/panels/display/scrollarea.h +++ b/panels/display/scrollarea.h @@ -34,6 +34,8 @@ typedef enum { FOO_BUTTON_PRESS, FOO_BUTTON_RELEASE, + FOO_DRAG_HOVER, + FOO_DROP, FOO_MOTION } FooScrollAreaEventType; @@ -115,7 +117,8 @@ void foo_scroll_area_invalidate_rect (FooScrollArea *scroll_area, void foo_scroll_area_begin_grab (FooScrollArea *scroll_area, FooScrollAreaEventFunc func, gpointer input_data); -void foo_scroll_area_end_grab (FooScrollArea *scroll_area); +void foo_scroll_area_end_grab (FooScrollArea *scroll_area, + FooScrollAreaEvent *event); gboolean foo_scroll_area_is_grabbed (FooScrollArea *scroll_area); void foo_scroll_area_begin_auto_scroll (FooScrollArea *scroll_area); diff --git a/panels/display/xrandr-capplet.c b/panels/display/xrandr-capplet.c index 1919aff7b..2661718fd 100644 --- a/panels/display/xrandr-capplet.c +++ b/panels/display/xrandr-capplet.c @@ -1467,6 +1467,62 @@ set_cursor (GtkWidget *widget, GdkCursorType type) gdk_cursor_unref (cursor); } +static void +set_top_bar_tooltip (App *app, gboolean is_dragging) +{ + const char *text; + + if (is_dragging) + text = NULL; + else + text = _("Drag to change primary display."); + + gtk_widget_set_tooltip_text (app->area, text); +} + +static void +on_top_bar_event (FooScrollArea *area, + FooScrollAreaEvent *event, + App *app) +{ + /* Ignore drops */ + if (event->type == FOO_DROP) + return; + + /* If the mouse is inside the top bar, set the cursor to "you can move me". See + * on_canvas_event() for where we reset the cursor to the default if it + * exits the outputs' area. + */ + if (!app->current_configuration->clone && get_n_connected (app) > 1) + set_cursor (GTK_WIDGET (area), GDK_FLEUR); + + if (event->type == FOO_BUTTON_PRESS) + { + rebuild_gui (app); + set_top_bar_tooltip (app, TRUE); + + if (!app->current_configuration->clone && get_n_connected (app) > 1) + { + foo_scroll_area_begin_grab (area, (FooScrollAreaEventFunc) on_top_bar_event, app); + } + + foo_scroll_area_invalidate (area); + } + else + { + if (foo_scroll_area_is_grabbed (area)) + { + if (event->type == FOO_BUTTON_RELEASE) + { + foo_scroll_area_end_grab (area, event); + set_top_bar_tooltip (app, FALSE); + } + + foo_scroll_area_invalidate (area); + } + } +} + static void set_monitors_tooltip (App *app, gboolean is_dragging) { @@ -1480,6 +1536,27 @@ set_monitors_tooltip (App *app, gboolean is_dragging) gtk_widget_set_tooltip_text (app->area, text); } +static void +set_primary_output (App *app, + GnomeOutputInfo *output) +{ + int i; + + for (i = 0; app->current_configuration->outputs[i] != NULL; ++i) + { + GnomeOutputInfo *output2 = app->current_configuration->outputs[i]; + if (output2 != output) + { + output2->primary = FALSE; + } + else + { + output2->primary = TRUE; + } + } + +} + static void on_output_event (FooScrollArea *area, FooScrollAreaEvent *event, @@ -1488,6 +1565,18 @@ on_output_event (FooScrollArea *area, GnomeOutputInfo *output = data; App *app = g_object_get_data (G_OBJECT (area), "app"); + if (event->type == FOO_DRAG_HOVER) + { + set_primary_output (app, output); + return; + } + + if (event->type == FOO_DROP) + { + /* Activate new primary? */ + return; + } + /* If the mouse is inside the outputs, set the cursor to "you can move me". See * on_canvas_event() for where we reset the cursor to the default if it * exits the outputs' area. @@ -1579,7 +1668,7 @@ on_output_event (FooScrollArea *area, if (event->type == FOO_BUTTON_RELEASE) { - foo_scroll_area_end_grab (area); + foo_scroll_area_end_grab (area, NULL); set_monitors_tooltip (app, FALSE); g_free (output->user_data); @@ -1811,6 +1900,11 @@ paint_output (App *app, cairo_t *cr, int i) /* top bar */ cairo_rectangle (cr, x, y, w * scale + 0.5, 20); cairo_set_source_rgb (cr, 0, 0, 0); + foo_scroll_area_add_input_from_fill (FOO_SCROLL_AREA (app->area), + cr, + (FooScrollAreaEventFunc) on_top_bar_event, + app); + cairo_fill (cr); /* clock */ @@ -1846,7 +1940,6 @@ paint_output (App *app, cairo_t *cr, int i) pango_cairo_show_layout (cr, layout); g_object_unref (layout); - } cairo_restore (cr);