display: allow dragging top bar to set primary display

This commit is contained in:
William Jon McCann 2010-11-20 20:38:04 -05:00
parent 3337e01c00
commit 7e5aecdf98
3 changed files with 118 additions and 12 deletions

View file

@ -763,9 +763,6 @@ emit_input (FooScrollArea *scroll_area,
if (!func) if (!func)
return; return;
if (type != FOO_MOTION)
emit_input (scroll_area, FOO_MOTION, x, y, func, data);
event.type = type; event.type = type;
event.x = x; event.x = x;
event.y = y; event.y = y;
@ -789,7 +786,6 @@ process_event (FooScrollArea *scroll_area,
emit_input (scroll_area, input_type, x, y, emit_input (scroll_area, input_type, x, y,
scroll_area->priv->grab_func, scroll_area->priv->grab_func,
scroll_area->priv->grab_data); scroll_area->priv->grab_data);
return;
} }
#if 0 #if 0
@ -828,10 +824,20 @@ process_event (FooScrollArea *scroll_area,
if (inside) if (inside)
{ {
emit_input (scroll_area, input_type, if (scroll_area->priv->grabbed)
x, y, {
path->func, emit_input (scroll_area, FOO_DRAG_HOVER,
path->data); x, y,
path->func,
path->data);
}
else
{
emit_input (scroll_area, input_type,
x, y,
path->func,
path->data);
}
return; return;
} }
@ -1322,13 +1328,17 @@ foo_scroll_area_begin_grab (FooScrollArea *scroll_area,
} }
void 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)); g_return_if_fail (FOO_IS_SCROLL_AREA (scroll_area));
scroll_area->priv->grabbed = FALSE; scroll_area->priv->grabbed = FALSE;
scroll_area->priv->grab_func = NULL; scroll_area->priv->grab_func = NULL;
scroll_area->priv->grab_data = NULL; scroll_area->priv->grab_data = NULL;
if (event != NULL)
process_event (scroll_area, FOO_DROP, event->x, event->y);
} }
gboolean gboolean

View file

@ -34,6 +34,8 @@ typedef enum
{ {
FOO_BUTTON_PRESS, FOO_BUTTON_PRESS,
FOO_BUTTON_RELEASE, FOO_BUTTON_RELEASE,
FOO_DRAG_HOVER,
FOO_DROP,
FOO_MOTION FOO_MOTION
} FooScrollAreaEventType; } FooScrollAreaEventType;
@ -115,7 +117,8 @@ void foo_scroll_area_invalidate_rect (FooScrollArea *scroll_area,
void foo_scroll_area_begin_grab (FooScrollArea *scroll_area, void foo_scroll_area_begin_grab (FooScrollArea *scroll_area,
FooScrollAreaEventFunc func, FooScrollAreaEventFunc func,
gpointer input_data); 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); gboolean foo_scroll_area_is_grabbed (FooScrollArea *scroll_area);
void foo_scroll_area_begin_auto_scroll (FooScrollArea *scroll_area); void foo_scroll_area_begin_auto_scroll (FooScrollArea *scroll_area);

View file

@ -1467,6 +1467,62 @@ set_cursor (GtkWidget *widget, GdkCursorType type)
gdk_cursor_unref (cursor); 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 static void
set_monitors_tooltip (App *app, gboolean is_dragging) 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); 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 static void
on_output_event (FooScrollArea *area, on_output_event (FooScrollArea *area,
FooScrollAreaEvent *event, FooScrollAreaEvent *event,
@ -1488,6 +1565,18 @@ on_output_event (FooScrollArea *area,
GnomeOutputInfo *output = data; GnomeOutputInfo *output = data;
App *app = g_object_get_data (G_OBJECT (area), "app"); 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 /* 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 * on_canvas_event() for where we reset the cursor to the default if it
* exits the outputs' area. * exits the outputs' area.
@ -1579,7 +1668,7 @@ on_output_event (FooScrollArea *area,
if (event->type == FOO_BUTTON_RELEASE) if (event->type == FOO_BUTTON_RELEASE)
{ {
foo_scroll_area_end_grab (area); foo_scroll_area_end_grab (area, NULL);
set_monitors_tooltip (app, FALSE); set_monitors_tooltip (app, FALSE);
g_free (output->user_data); g_free (output->user_data);
@ -1811,6 +1900,11 @@ paint_output (App *app, cairo_t *cr, int i)
/* top bar */ /* top bar */
cairo_rectangle (cr, x, y, w * scale + 0.5, 20); cairo_rectangle (cr, x, y, w * scale + 0.5, 20);
cairo_set_source_rgb (cr, 0, 0, 0); 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); cairo_fill (cr);
/* clock */ /* clock */
@ -1846,7 +1940,6 @@ paint_output (App *app, cairo_t *cr, int i)
pango_cairo_show_layout (cr, layout); pango_cairo_show_layout (cr, layout);
g_object_unref (layout); g_object_unref (layout);
} }
cairo_restore (cr); cairo_restore (cr);