Merge lp:~ayatana-scrollbar-team/overlay-scrollbar/use-backdrop-state-flag-instead-root-filter into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Ted Gould
Approved revision: 346
Merged at revision: 346
Proposed branch: lp:~ayatana-scrollbar-team/overlay-scrollbar/use-backdrop-state-flag-instead-root-filter
Merge into: lp:overlay-scrollbar
Diff against target: 386 lines (+117/-87)
1 file modified
os/os-scrollbar.c (+117/-87)
To merge this branch: bzr merge lp:~ayatana-scrollbar-team/overlay-scrollbar/use-backdrop-state-flag-instead-root-filter
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+104789@code.launchpad.net

Description of the change

Try removing code not needed with latest gtk3

To post a comment you must log in.
Revision history for this message
Andrea Cimitan (cimi) wrote :

I know the #ifdef are ugly, but gtk+2 doesn't have backdrop state flag...

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 2012-04-27 13:49:56 +0000
+++ os/os-scrollbar.c 2012-05-04 18:27:26 +0000
@@ -125,7 +125,9 @@
125 OsWindowFilter filter;125 OsWindowFilter filter;
126 gboolean active_window;126 gboolean active_window;
127 gboolean allow_resize;127 gboolean allow_resize;
128#ifdef USE_GTK3
128 gboolean deactivable_bar;129 gboolean deactivable_bar;
130#endif
129 gboolean hidable_thumb;131 gboolean hidable_thumb;
130 gboolean window_button_press; /* FIXME(Cimi) to replace with X11 input events. */132 gboolean window_button_press; /* FIXME(Cimi) to replace with X11 input events. */
131 gdouble value;133 gdouble value;
@@ -573,6 +575,7 @@
573 return value;575 return value;
574}576}
575577
578#ifdef USE_GTK3
576/* Deactivate the bar if it's the case. */579/* Deactivate the bar if it's the case. */
577static void580static void
578deactivate_bar (GtkScrollbar *scrollbar)581deactivate_bar (GtkScrollbar *scrollbar)
@@ -602,6 +605,7 @@
602605
603 return FALSE;606 return FALSE;
604}607}
608#endif
605609
606/* Get the private struct. */610/* Get the private struct. */
607static OsScrollbarPrivate*611static OsScrollbarPrivate*
@@ -647,7 +651,9 @@
647651
648 /* Initialize struct variables. */652 /* Initialize struct variables. */
649 qdata->side = OS_SIDE_RIGHT;653 qdata->side = OS_SIDE_RIGHT;
654#ifdef USE_GTK3
650 qdata->deactivable_bar = TRUE;655 qdata->deactivable_bar = TRUE;
656#endif
651 qdata->hidable_thumb = TRUE;657 qdata->hidable_thumb = TRUE;
652 qdata->fine_scroll_multiplier = 1.0;658 qdata->fine_scroll_multiplier = 1.0;
653 qdata->bar = os_bar_new ();659 qdata->bar = os_bar_new ();
@@ -1480,6 +1486,7 @@
1480 move_bar (scrollbar);1486 move_bar (scrollbar);
1481}1487}
14821488
1489#ifdef USE_GTK3
1483/* Bar functions. */1490/* Bar functions. */
14841491
1485/* Set the state of the bar checking mouse position. */1492/* Set the state of the bar checking mouse position. */
@@ -1509,89 +1516,10 @@
1509 os_bar_set_active (priv->bar, FALSE, TRUE);1516 os_bar_set_active (priv->bar, FALSE, TRUE);
1510 }1517 }
1511}1518}
1519#endif
15121520
1513/* Root window functions. */1521/* Root window functions. */
15141522
1515/* React on active window changes. */
1516static void
1517root_gfunc (gpointer data,
1518 gpointer user_data)
1519{
1520 GtkScrollbar *scrollbar;
1521 OsScrollbarPrivate *priv;
1522
1523 scrollbar = GTK_SCROLLBAR (data);
1524 priv = get_private (GTK_WIDGET (scrollbar));
1525
1526 OS_DCHECK (scrollbar != NULL);
1527
1528 /* Return if the scrollbar is insensitive. */
1529 if (is_insensitive (scrollbar))
1530 return;
1531
1532 if (gtk_widget_get_mapped (GTK_WIDGET (scrollbar)))
1533 {
1534 if (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar))) ==
1535 gdk_screen_get_active_window (gtk_widget_get_screen (GTK_WIDGET (scrollbar))))
1536 {
1537 /* Stops potential running timeout. */
1538 if (priv->source_deactivate_bar_id != 0)
1539 {
1540 g_source_remove (priv->source_deactivate_bar_id);
1541 priv->source_deactivate_bar_id = 0;
1542 }
1543
1544 priv->active_window = TRUE;
1545
1546 priv->deactivable_bar = FALSE;
1547 os_bar_set_active (priv->bar, TRUE, TRUE);
1548 }
1549 else if (priv->active_window)
1550 {
1551 GdkWindow *parent;
1552 GdkWindow *window;
1553 const gint64 current_time = g_get_monotonic_time ();
1554 const gint64 end_time = priv->present_time + TIMEOUT_PRESENT_WINDOW * 1000;
1555
1556 priv->active_window = FALSE;
1557
1558 /* Loop through parent windows until it reaches
1559 * either an unknown GdkWindow (NULL),
1560 * or the toplevel window. */
1561 window = gtk_widget_get_window (GTK_WIDGET (scrollbar));
1562 parent = window_at_pointer (window, NULL, NULL);
1563 while (parent != NULL)
1564 {
1565 if (window == parent)
1566 break;
1567
1568 parent = gdk_window_get_parent (parent);
1569 }
1570
1571 if (parent != NULL)
1572 {
1573 gint x, y;
1574
1575 window_get_pointer (window, &x, &y, NULL);
1576
1577 /* When the window is unfocused,
1578 * check the position of the pointer
1579 * and set the state accordingly. */
1580 bar_set_state_from_pointer (scrollbar, x, y);
1581 }
1582 else
1583 {
1584 /* If the pointer is outside of the window, set it inactive. */
1585 priv->deactivable_bar = TRUE;
1586 os_bar_set_active (priv->bar, FALSE, TRUE);
1587 }
1588
1589 if ((current_time > end_time) && priv->thumb != NULL)
1590 gtk_widget_hide (priv->thumb);
1591 }
1592 }
1593}
1594
1595/* Filter function applied to the root window. */1523/* Filter function applied to the root window. */
1596static GdkFilterReturn1524static GdkFilterReturn
1597root_filter_func (GdkXEvent *gdkxevent,1525root_filter_func (GdkXEvent *gdkxevent,
@@ -1604,11 +1532,7 @@
16041532
1605 if (xev->type == PropertyNotify)1533 if (xev->type == PropertyNotify)
1606 {1534 {
1607 if (xev->xproperty.atom == net_active_window_atom)1535 if (xev->xproperty.atom == unity_net_workarea_region_atom)
1608 {
1609 g_slist_foreach (os_root_list, root_gfunc, NULL);
1610 }
1611 else if (xev->xproperty.atom == unity_net_workarea_region_atom)
1612 {1536 {
1613 calc_workarea (xev->xany.display, xev->xany.window);1537 calc_workarea (xev->xany.display, xev->xany.window);
1614 }1538 }
@@ -1914,7 +1838,9 @@
19141838
1915 priv->event |= OS_EVENT_ENTER_NOTIFY;1839 priv->event |= OS_EVENT_ENTER_NOTIFY;
19161840
1841#ifdef USE_GTK3
1917 priv->deactivable_bar = FALSE;1842 priv->deactivable_bar = FALSE;
1843#endif
1918 priv->hidable_thumb = FALSE;1844 priv->hidable_thumb = FALSE;
19191845
1920 if (priv->state & OS_STATE_INTERNAL)1846 if (priv->state & OS_STATE_INTERNAL)
@@ -1986,6 +1912,7 @@
1986 * not interacting with the thumb. */1912 * not interacting with the thumb. */
1987 if (!(priv->event & OS_EVENT_BUTTON_PRESS))1913 if (!(priv->event & OS_EVENT_BUTTON_PRESS))
1988 {1914 {
1915#ifdef USE_GTK3
1989 /* Never deactivate the bar in an active window. */1916 /* Never deactivate the bar in an active window. */
1990 if (!priv->active_window)1917 if (!priv->active_window)
1991 {1918 {
@@ -1998,6 +1925,7 @@
1998 deactivate_bar_cb,1925 deactivate_bar_cb,
1999 scrollbar);1926 scrollbar);
2000 }1927 }
1928#endif
20011929
2002 priv->event &= ~(OS_EVENT_ENTER_NOTIFY);1930 priv->event &= ~(OS_EVENT_ENTER_NOTIFY);
20031931
@@ -2029,9 +1957,11 @@
2029 scrollbar = GTK_SCROLLBAR (user_data);1957 scrollbar = GTK_SCROLLBAR (user_data);
2030 priv = get_private (GTK_WIDGET (scrollbar));1958 priv = get_private (GTK_WIDGET (scrollbar));
20311959
1960#ifdef USE_GTK3
2032 /* Immediately set the bar to be active. */1961 /* Immediately set the bar to be active. */
2033 priv->deactivable_bar = FALSE;1962 priv->deactivable_bar = FALSE;
2034 os_bar_set_active (priv->bar, TRUE, FALSE);1963 os_bar_set_active (priv->bar, TRUE, FALSE);
1964#endif
20351965
2036 xid = GDK_WINDOW_XID (gtk_widget_get_window (widget));1966 xid = GDK_WINDOW_XID (gtk_widget_get_window (widget));
2037 xid_parent = GDK_WINDOW_XID (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar))));1967 xid_parent = GDK_WINDOW_XID (gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (scrollbar))));
@@ -2566,6 +2496,7 @@
2566 const gint64 current_time = g_get_monotonic_time ();2496 const gint64 current_time = g_get_monotonic_time ();
2567 const gint64 end_time = priv->present_time + TIMEOUT_PRESENT_WINDOW * 1000;2497 const gint64 end_time = priv->present_time + TIMEOUT_PRESENT_WINDOW * 1000;
25682498
2499#ifdef USE_GTK3
2569 /* If the widget is mapped, is not insentitive2500 /* If the widget is mapped, is not insentitive
2570 * and the configure-event happens after2501 * and the configure-event happens after
2571 * the PropertyNotify _NET_ACTIVE_WINDOW event,2502 * the PropertyNotify _NET_ACTIVE_WINDOW event,
@@ -2609,6 +2540,7 @@
2609 os_bar_set_active (priv->bar, TRUE, TRUE);2540 os_bar_set_active (priv->bar, TRUE, TRUE);
2610 }2541 }
2611 }2542 }
2543#endif
26122544
2613 if (current_time > end_time)2545 if (current_time > end_time)
2614 gtk_widget_hide (priv->thumb);2546 gtk_widget_hide (priv->thumb);
@@ -3027,6 +2959,7 @@
3027 {2959 {
3028 priv->window_button_press = FALSE;2960 priv->window_button_press = FALSE;
30292961
2962#ifdef USE_GTK3
3030 /* Never deactivate the bar in an active window. */2963 /* Never deactivate the bar in an active window. */
3031 if (!priv->active_window)2964 if (!priv->active_window)
3032 {2965 {
@@ -3039,6 +2972,7 @@
3039 deactivate_bar_cb,2972 deactivate_bar_cb,
3040 scrollbar);2973 scrollbar);
3041 }2974 }
2975#endif
30422976
3043 if (gtk_widget_get_mapped (priv->thumb) &&2977 if (gtk_widget_get_mapped (priv->thumb) &&
3044 !(priv->event & OS_EVENT_BUTTON_PRESS))2978 !(priv->event & OS_EVENT_BUTTON_PRESS))
@@ -3070,10 +3004,12 @@
3070 /* Get the motion_notify_event trough XEvent. */3004 /* Get the motion_notify_event trough XEvent. */
3071 if (!priv->window_button_press && os_xevent == OS_XEVENT_MOTION)3005 if (!priv->window_button_press && os_xevent == OS_XEVENT_MOTION)
3072 {3006 {
3007#ifdef USE_GTK3
3073 /* React to motion_notify_event3008 /* React to motion_notify_event
3074 * and set the state accordingly. */3009 * and set the state accordingly. */
3075 if (!is_insensitive (scrollbar) && !priv->active_window)3010 if (!is_insensitive (scrollbar) && !priv->active_window)
3076 bar_set_state_from_pointer (scrollbar, event_x, event_y);3011 bar_set_state_from_pointer (scrollbar, event_x, event_y);
3012#endif
30773013
3078 /* Proximity area. */3014 /* Proximity area. */
3079 if (check_proximity (scrollbar, event_x, event_y))3015 if (check_proximity (scrollbar, event_x, event_y))
@@ -3335,6 +3271,15 @@
3335 (* pre_hijacked_scrollbar_hide) (widget);3271 (* pre_hijacked_scrollbar_hide) (widget);
3336}3272}
33373273
3274#ifdef USE_GTK3
3275/* Return TRUE if the widget is in backdrop window. */
3276static gboolean
3277is_backdrop_window (GtkWidget *widget)
3278{
3279 return (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_BACKDROP) != 0;
3280}
3281#endif
3282
3338static void3283static void
3339hijacked_scrollbar_map (GtkWidget *widget)3284hijacked_scrollbar_map (GtkWidget *widget)
3340{3285{
@@ -3348,9 +3293,9 @@
33483293
3349 (* widget_class_map) (widget);3294 (* widget_class_map) (widget);
33503295
3296#ifdef USE_GTK3
3351 /* On map, check for the active window. */3297 /* On map, check for the active window. */
3352 if (gtk_widget_get_window (gtk_widget_get_toplevel (widget)) ==3298 if (!is_backdrop_window (GTK_WIDGET (scrollbar)))
3353 gdk_screen_get_active_window (gtk_widget_get_screen (widget)))
3354 {3299 {
3355 /* Stops potential running timeout. */3300 /* Stops potential running timeout. */
3356 if (priv->source_deactivate_bar_id != 0)3301 if (priv->source_deactivate_bar_id != 0)
@@ -3386,6 +3331,7 @@
3386 os_bar_set_active (priv->bar, TRUE, FALSE);3331 os_bar_set_active (priv->bar, TRUE, FALSE);
3387 }3332 }
3388 }3333 }
3334#endif
33893335
3390 if (!(priv->state & OS_STATE_FULLSIZE))3336 if (!(priv->state & OS_STATE_FULLSIZE))
3391 os_bar_show (priv->bar);3337 os_bar_show (priv->bar);
@@ -3653,7 +3599,9 @@
3653 priv->filter.proximity = FALSE;3599 priv->filter.proximity = FALSE;
3654 remove_window_filter (scrollbar);3600 remove_window_filter (scrollbar);
36553601
3602#ifdef USE_GTK3
3656 os_bar_set_active (priv->bar, FALSE, FALSE);3603 os_bar_set_active (priv->bar, FALSE, FALSE);
3604#endif
36573605
3658 gtk_widget_hide (priv->thumb);3606 gtk_widget_hide (priv->thumb);
3659}3607}
@@ -3675,6 +3623,7 @@
3675 add_window_filter (scrollbar);3623 add_window_filter (scrollbar);
3676 }3624 }
36773625
3626#ifdef USE_GTK3
3678 if (priv->active_window)3627 if (priv->active_window)
3679 os_bar_set_active (priv->bar, TRUE, FALSE);3628 os_bar_set_active (priv->bar, TRUE, FALSE);
3680 else if (gtk_widget_get_realized (GTK_WIDGET (scrollbar)))3629 else if (gtk_widget_get_realized (GTK_WIDGET (scrollbar)))
@@ -3688,9 +3637,86 @@
3688 * and set the state accordingly. */3637 * and set the state accordingly. */
3689 bar_set_state_from_pointer (scrollbar, x, y);3638 bar_set_state_from_pointer (scrollbar, x, y);
3690 }3639 }
3640#endif
3691}3641}
36923642
3693#ifdef USE_GTK33643#ifdef USE_GTK3
3644/* React on active window changes. */
3645static void
3646backdrop_state_flag_changed (GtkScrollbar *scrollbar)
3647{
3648 OsScrollbarPrivate *priv;
3649
3650 priv = get_private (GTK_WIDGET (scrollbar));
3651
3652 OS_DCHECK (scrollbar != NULL);
3653
3654 /* Return if the scrollbar is insensitive. */
3655 if (is_insensitive (scrollbar))
3656 return;
3657
3658 if (gtk_widget_get_mapped (GTK_WIDGET (scrollbar)))
3659 {
3660 if (!is_backdrop_window (GTK_WIDGET (scrollbar)))
3661 {
3662 /* Stops potential running timeout. */
3663 if (priv->source_deactivate_bar_id != 0)
3664 {
3665 g_source_remove (priv->source_deactivate_bar_id);
3666 priv->source_deactivate_bar_id = 0;
3667 }
3668
3669 priv->active_window = TRUE;
3670
3671 priv->deactivable_bar = FALSE;
3672 os_bar_set_active (priv->bar, TRUE, TRUE);
3673 }
3674 else if (priv->active_window)
3675 {
3676 GdkWindow *parent;
3677 GdkWindow *window;
3678 const gint64 current_time = g_get_monotonic_time ();
3679 const gint64 end_time = priv->present_time + TIMEOUT_PRESENT_WINDOW * 1000;
3680
3681 priv->active_window = FALSE;
3682
3683 /* Loop through parent windows until it reaches
3684 * either an unknown GdkWindow (NULL),
3685 * or the toplevel window. */
3686 window = gtk_widget_get_window (GTK_WIDGET (scrollbar));
3687 parent = window_at_pointer (window, NULL, NULL);
3688 while (parent != NULL)
3689 {
3690 if (window == parent)
3691 break;
3692
3693 parent = gdk_window_get_parent (parent);
3694 }
3695
3696 if (parent != NULL)
3697 {
3698 gint x, y;
3699
3700 window_get_pointer (window, &x, &y, NULL);
3701
3702 /* When the window is unfocused,
3703 * check the position of the pointer
3704 * and set the state accordingly. */
3705 bar_set_state_from_pointer (scrollbar, x, y);
3706 }
3707 else
3708 {
3709 /* If the pointer is outside of the window, set it inactive. */
3710 priv->deactivable_bar = TRUE;
3711 os_bar_set_active (priv->bar, FALSE, TRUE);
3712 }
3713
3714 if ((current_time > end_time) && priv->thumb != NULL)
3715 gtk_widget_hide (priv->thumb);
3716 }
3717 }
3718}
3719
3694static void3720static void
3695hijacked_scrollbar_state_flags_changed (GtkWidget *widget,3721hijacked_scrollbar_state_flags_changed (GtkWidget *widget,
3696 GtkStateFlags flags)3722 GtkStateFlags flags)
@@ -3699,6 +3725,10 @@
36993725
3700 scrollbar = GTK_SCROLLBAR (widget);3726 scrollbar = GTK_SCROLLBAR (widget);
37013727
3728 if ((flags & GTK_STATE_FLAG_BACKDROP) !=
3729 (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_BACKDROP))
3730 backdrop_state_flag_changed (scrollbar);
3731
3702 /* Only set the new state if the right bit changed. */3732 /* Only set the new state if the right bit changed. */
3703 if ((flags & GTK_STATE_FLAG_INSENSITIVE) !=3733 if ((flags & GTK_STATE_FLAG_INSENSITIVE) !=
3704 (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_INSENSITIVE))3734 (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_INSENSITIVE))

Subscribers

People subscribed via source and target branches