Merge lp:~cimi/overlay-scrollbar/new-locked-mode into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 319
Merged at revision: 317
Proposed branch: lp:~cimi/overlay-scrollbar/new-locked-mode
Merge into: lp:overlay-scrollbar
Diff against target: 280 lines (+40/-160)
1 file modified
os/os-scrollbar.c (+40/-160)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/new-locked-mode
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+83960@code.launchpad.net

Description of the change

New logic for locked mode. Lock mode is when the thumb is internal (touching the screen or a strut), now it is unlocked when you exit the thumb horizontally or in particular proximity areas

To post a comment you must log in.
319. By Andrea Cimitan

Cosmetic change

Revision history for this message
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'os/os-scrollbar.c'
--- os/os-scrollbar.c 2011-10-20 23:06:36 +0000
+++ os/os-scrollbar.c 2011-11-30 16:34:25 +0000
@@ -1624,6 +1624,15 @@
1624 scrollbar = OS_SCROLLBAR (user_data);1624 scrollbar = OS_SCROLLBAR (user_data);
1625 priv = scrollbar->priv;1625 priv = scrollbar->priv;
16261626
1627 /* When exiting the thumb horizontally (or vertically),
1628 * in LOCKED state, remove the lock. */
1629 if ((priv->state & OS_STATE_LOCKED) &&
1630 ((priv->side == OS_SIDE_RIGHT && event->x < 0) ||
1631 (priv->side == OS_SIDE_BOTTOM && event->y < 0) ||
1632 (priv->side == OS_SIDE_LEFT && event->x - priv->thumb_all.width >= 0) ||
1633 (priv->side == OS_SIDE_TOP && event->y - priv->thumb_all.height >= 0)))
1634 priv->state &= ~(OS_STATE_LOCKED);
1635
1627 /* Add the timeouts only if you are1636 /* Add the timeouts only if you are
1628 * not interacting with the thumb. */1637 * not interacting with the thumb. */
1629 if (!(priv->event & OS_EVENT_BUTTON_PRESS))1638 if (!(priv->event & OS_EVENT_BUTTON_PRESS))
@@ -2160,6 +2169,26 @@
21602169
2161 gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos);2170 gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (scrollbar)), &x_pos, &y_pos);
21622171
2172 if (priv->state & OS_STATE_LOCKED)
2173 {
2174 gint x_pos_t, y_pos_t;
2175
2176 gdk_window_get_origin (gtk_widget_get_window (priv->thumb), &x_pos_t, &y_pos_t);
2177
2178 /* If the pointer is moving in the area of the proximity
2179 * at the left of the thumb (so, not vertically intercepting the thumb),
2180 * unlock it. Viceversa for the horizontal orientation.
2181 * The flag OS_STATE_LOCKED is set only for a mapped thumb,
2182 * so we can freely ask for its position and do our calculations. */
2183 if ((priv->side == OS_SIDE_RIGHT && x_pos + event_x <= x_pos_t) ||
2184 (priv->side == OS_SIDE_BOTTOM && y_pos + event_y <= y_pos_t) ||
2185 (priv->side == OS_SIDE_LEFT && x_pos + event_x >= x_pos_t + priv->thumb_all.width) ||
2186 (priv->side == OS_SIDE_TOP && y_pos + event_y >= y_pos_t + priv->thumb_all.height))
2187 priv->state &= ~(OS_STATE_LOCKED);
2188 else
2189 return;
2190 }
2191
2163 /* Calculate priv->thumb_win.x and priv->thumb_win.y2192 /* Calculate priv->thumb_win.x and priv->thumb_win.y
2164 * (thumb window allocation in root coordinates).2193 * (thumb window allocation in root coordinates).
2165 * I guess it's faster to store these values,2194 * I guess it's faster to store these values,
@@ -2382,7 +2411,6 @@
2382}2411}
23832412
2384/* Filter function applied to the toplevel window. */2413/* Filter function applied to the toplevel window. */
2385#ifdef USE_GTK3
2386typedef enum2414typedef enum
2387{2415{
2388 OS_XEVENT_NONE,2416 OS_XEVENT_NONE,
@@ -2421,6 +2449,7 @@
2421 event_x = 0;2449 event_x = 0;
2422 event_y = 0;2450 event_y = 0;
24232451
2452#ifdef USE_GTK3
2424 if (xev->type == GenericEvent)2453 if (xev->type == GenericEvent)
2425 {2454 {
2426 /* Deal with XInput 2 events. */2455 /* Deal with XInput 2 events. */
@@ -2450,6 +2479,7 @@
2450 }2479 }
2451 else2480 else
2452 {2481 {
2482#endif
2453 /* Deal with X core events, when apps (like rhythmbox),2483 /* Deal with X core events, when apps (like rhythmbox),
2454 * are using gdk_disable_miltidevice (). */2484 * are using gdk_disable_miltidevice (). */
2455 if (xev->type == ButtonPress)2485 if (xev->type == ButtonPress)
@@ -2471,7 +2501,9 @@
2471 event_x = xev->xmotion.x;2501 event_x = xev->xmotion.x;
2472 event_y = xev->xmotion.y;2502 event_y = xev->xmotion.y;
2473 }2503 }
2504#ifdef USE_GTK3
2474 }2505 }
2506#endif
24752507
2476 if (os_xevent == OS_XEVENT_BUTTON_PRESS)2508 if (os_xevent == OS_XEVENT_BUTTON_PRESS)
2477 {2509 {
@@ -2495,14 +2527,12 @@
2495 {2527 {
2496 priv->hidable_thumb = FALSE;2528 priv->hidable_thumb = FALSE;
24972529
2530 adjust_thumb_position (scrollbar, event_x, event_y);
2531
2498 if (priv->state & OS_STATE_LOCKED)2532 if (priv->state & OS_STATE_LOCKED)
2499 return GDK_FILTER_CONTINUE;2533 return GDK_FILTER_CONTINUE;
25002534
2501 adjust_thumb_position (scrollbar, event_x, event_y);2535 show_thumb (scrollbar);
2502
2503 gtk_widget_show (priv->thumb);
2504
2505 update_tail (scrollbar);
2506 }2536 }
2507 }2537 }
25082538
@@ -2569,11 +2599,11 @@
2569 priv->source_hide_thumb_id = 0;2599 priv->source_hide_thumb_id = 0;
2570 }2600 }
25712601
2602 adjust_thumb_position (scrollbar, event_x, event_y);
2603
2572 if (priv->state & OS_STATE_LOCKED)2604 if (priv->state & OS_STATE_LOCKED)
2573 return GDK_FILTER_CONTINUE;2605 return GDK_FILTER_CONTINUE;
25742606
2575 adjust_thumb_position (scrollbar, event_x, event_y);
2576
2577 show_thumb (scrollbar);2607 show_thumb (scrollbar);
2578 }2608 }
2579 else2609 else
@@ -2602,158 +2632,6 @@
26022632
2603 return GDK_FILTER_CONTINUE;2633 return GDK_FILTER_CONTINUE;
2604}2634}
2605#else
2606static GdkFilterReturn
2607window_filter_func (GdkXEvent *gdkxevent,
2608 GdkEvent *event,
2609 gpointer user_data)
2610{
2611 OsScrollbar *scrollbar;
2612 OsScrollbarPrivate *priv;
2613 XEvent *xev;
2614
2615 g_return_val_if_fail (OS_IS_SCROLLBAR (user_data), GDK_FILTER_CONTINUE);
2616
2617 scrollbar = OS_SCROLLBAR (user_data);
2618 priv = scrollbar->priv;
2619
2620 xev = gdkxevent;
2621
2622 g_return_val_if_fail (OS_IS_BAR (priv->bar), GDK_FILTER_CONTINUE);
2623 g_return_val_if_fail (OS_IS_THUMB (priv->thumb), GDK_FILTER_CONTINUE);
2624
2625 if (!(priv->state & OS_STATE_FULLSIZE))
2626 {
2627 if (xev->type == ButtonPress)
2628 {
2629 priv->window_button_press = TRUE;
2630
2631 if (priv->source_show_thumb_id != 0)
2632 {
2633 g_source_remove (priv->source_show_thumb_id);
2634 priv->source_show_thumb_id = 0;
2635 }
2636
2637 gtk_widget_hide (priv->thumb);
2638 }
2639
2640 if (priv->window_button_press && xev->type == ButtonRelease)
2641 {
2642 priv->window_button_press = FALSE;
2643
2644 /* Proximity area. */
2645 if (check_proximity (scrollbar, xev->xbutton.x, xev->xbutton.y))
2646 {
2647 priv->hidable_thumb = FALSE;
2648
2649 if (priv->state & OS_STATE_LOCKED)
2650 return GDK_FILTER_CONTINUE;
2651
2652 adjust_thumb_position (scrollbar, xev->xbutton.x, xev->xbutton.y);
2653
2654 gtk_widget_show (priv->thumb);
2655
2656 update_tail (scrollbar);
2657 }
2658 }
2659
2660 if (xev->type == LeaveNotify)
2661 {
2662 priv->window_button_press = FALSE;
2663
2664 /* Never deactivate the bar in an active window. */
2665 if (!priv->active_window)
2666 {
2667 priv->deactivable_bar = TRUE;
2668
2669 if (priv->source_deactivate_bar_id != 0)
2670 g_source_remove (priv->source_deactivate_bar_id);
2671
2672 priv->source_deactivate_bar_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
2673 deactivate_bar_cb,
2674 scrollbar);
2675 }
2676
2677 if (gtk_widget_get_mapped (priv->thumb) &&
2678 !(priv->event & OS_EVENT_BUTTON_PRESS))
2679 {
2680 priv->hidable_thumb = TRUE;
2681
2682 if (priv->source_hide_thumb_id != 0)
2683 g_source_remove (priv->source_hide_thumb_id);
2684
2685 priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
2686 hide_thumb_cb,
2687 scrollbar);
2688 }
2689
2690 if (priv->source_show_thumb_id != 0)
2691 {
2692 g_source_remove (priv->source_show_thumb_id);
2693 priv->source_show_thumb_id = 0;
2694 }
2695
2696 if (priv->source_unlock_thumb_id != 0)
2697 g_source_remove (priv->source_unlock_thumb_id);
2698
2699 priv->source_unlock_thumb_id = g_timeout_add (TIMEOUT_TOPLEVEL_HIDE,
2700 unlock_thumb_cb,
2701 scrollbar);
2702 }
2703
2704 /* Get the motion_notify_event trough XEvent. */
2705 if (!priv->window_button_press && xev->type == MotionNotify)
2706 {
2707 /* React to motion_notify_event
2708 * and set the state accordingly. */
2709 if (!is_insensitive (scrollbar) && !priv->active_window)
2710 bar_set_state_from_pointer (scrollbar, xev->xmotion.x, xev->xmotion.y);
2711
2712 /* Proximity area. */
2713 if (check_proximity (scrollbar, xev->xmotion.x, xev->xmotion.y))
2714 {
2715 priv->hidable_thumb = FALSE;
2716
2717 if (priv->source_hide_thumb_id != 0)
2718 {
2719 g_source_remove (priv->source_hide_thumb_id);
2720 priv->source_hide_thumb_id = 0;
2721 }
2722
2723 if (priv->state & OS_STATE_LOCKED)
2724 return GDK_FILTER_CONTINUE;
2725
2726 adjust_thumb_position (scrollbar, xev->xmotion.x, xev->xmotion.y);
2727
2728 show_thumb (scrollbar);
2729 }
2730 else
2731 {
2732 priv->state &= ~(OS_STATE_LOCKED);
2733
2734 if (priv->source_show_thumb_id != 0)
2735 {
2736 g_source_remove (priv->source_show_thumb_id);
2737 priv->source_show_thumb_id = 0;
2738 }
2739
2740 if (gtk_widget_get_mapped (priv->thumb) &&
2741 !(priv->event & OS_EVENT_BUTTON_PRESS))
2742 {
2743 priv->hidable_thumb = TRUE;
2744
2745 if (priv->source_hide_thumb_id == 0)
2746 priv->source_hide_thumb_id = g_timeout_add (TIMEOUT_PROXIMITY_HIDE,
2747 hide_thumb_cb,
2748 scrollbar);
2749 }
2750 }
2751 }
2752 }
2753
2754 return GDK_FILTER_CONTINUE;
2755}
2756#endif
27572635
2758/* Add the window filter function. */2636/* Add the window filter function. */
2759static void2637static void
@@ -3130,6 +3008,8 @@
31303008
3131 gdk_window_set_events (gtk_widget_get_window (widget),3009 gdk_window_set_events (gtk_widget_get_window (widget),
3132 gdk_window_get_events (gtk_widget_get_window (widget)) |3010 gdk_window_get_events (gtk_widget_get_window (widget)) |
3011 GDK_BUTTON_PRESS_MASK |
3012 GDK_BUTTON_RELEASE_MASK |
3133 GDK_POINTER_MOTION_MASK);3013 GDK_POINTER_MOTION_MASK);
31343014
3135 if (priv->filter.proximity)3015 if (priv->filter.proximity)

Subscribers

People subscribed via source and target branches