[virt-tools-list] [PATCH virt-viewer 1/2] Move monitor alignment function to util header

Christophe Fergeau cfergeau at redhat.com
Wed Oct 22 09:36:22 UTC 2014


ACK, thanks for going the extra step of doing the split.

Christophe

On Wed, Oct 15, 2014 at 12:42:16PM -0500, Jonathon Jongsma wrote:
> ---
>  src/virt-viewer-session.c | 51 +----------------------------------------------
>  src/virt-viewer-util.c    | 50 ++++++++++++++++++++++++++++++++++++++++++++++
>  src/virt-viewer-util.h    |  3 +++
>  3 files changed, 54 insertions(+), 50 deletions(-)
> 
> diff --git a/src/virt-viewer-session.c b/src/virt-viewer-session.c
> index d9c84a6..d050ba1 100644
> --- a/src/virt-viewer-session.c
> +++ b/src/virt-viewer-session.c
> @@ -339,55 +339,6 @@ virt_viewer_session_init(VirtViewerSession *session)
>      session->priv = VIRT_VIEWER_SESSION_GET_PRIVATE(session);
>  }
>  
> -/* simple sorting of monitors. Primary sort left-to-right, secondary sort from
> - * top-to-bottom, finally by monitor id */
> -static int
> -displays_cmp(const void *p1, const void *p2, gpointer user_data)
> -{
> -    guint diff;
> -    GdkRectangle *displays = user_data;
> -    guint i = *(guint*)p1;
> -    guint j = *(guint*)p2;
> -    GdkRectangle *m1 = &displays[i];
> -    GdkRectangle *m2 = &displays[j];
> -    diff = m1->x - m2->x;
> -    if (diff == 0)
> -        diff = m1->y - m2->y;
> -    if (diff == 0)
> -        diff = i - j;
> -
> -    return diff;
> -}
> -
> -static void
> -virt_viewer_session_align_monitors_linear(GdkRectangle *displays, guint ndisplays)
> -{
> -    gint i, x = 0;
> -    guint *sorted_displays;
> -
> -    g_return_if_fail(displays != NULL);
> -
> -    if (ndisplays == 0)
> -        return;
> -
> -    sorted_displays = g_new0(guint, ndisplays);
> -    for (i = 0; i < ndisplays; i++)
> -        sorted_displays[i] = i;
> -    g_qsort_with_data(sorted_displays, ndisplays, sizeof(guint), displays_cmp, displays);
> -
> -    /* adjust monitor positions so that there's no gaps or overlap between
> -     * monitors */
> -    for (i = 0; i < ndisplays; i++) {
> -        guint nth = sorted_displays[i];
> -        g_assert(nth < ndisplays);
> -        GdkRectangle *rect = &displays[nth];
> -        rect->x = x;
> -        rect->y = 0;
> -        x += rect->width;
> -    }
> -    g_free(sorted_displays);
> -}
> -
>  static void
>  virt_viewer_session_on_monitor_geometry_changed(VirtViewerSession* self,
>                                                  VirtViewerDisplay* display G_GNUC_UNUSED)
> @@ -428,7 +379,7 @@ virt_viewer_session_on_monitor_geometry_changed(VirtViewerSession* self,
>      }
>  
>      if (!all_fullscreen)
> -        virt_viewer_session_align_monitors_linear(monitors, nmonitors);
> +        virt_viewer_align_monitors_linear(monitors, nmonitors);
>  
>      klass->apply_monitor_geometry(self, monitors, nmonitors);
>      g_free(monitors);
> diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c
> index 655f489..c46d07d 100644
> --- a/src/virt-viewer-util.c
> +++ b/src/virt-viewer-util.c
> @@ -488,6 +488,56 @@ end:
>      g_strfreev(v2);
>      return retval;
>  }
> +
> +/* simple sorting of monitors. Primary sort left-to-right, secondary sort from
> + * top-to-bottom, finally by monitor id */
> +static int
> +displays_cmp(const void *p1, const void *p2, gpointer user_data)
> +{
> +    guint diff;
> +    GdkRectangle *displays = user_data;
> +    guint i = *(guint*)p1;
> +    guint j = *(guint*)p2;
> +    GdkRectangle *m1 = &displays[i];
> +    GdkRectangle *m2 = &displays[j];
> +    diff = m1->x - m2->x;
> +    if (diff == 0)
> +        diff = m1->y - m2->y;
> +    if (diff == 0)
> +        diff = i - j;
> +
> +    return diff;
> +}
> +
> +void
> +virt_viewer_align_monitors_linear(GdkRectangle *displays, guint ndisplays)
> +{
> +    gint i, x = 0;
> +    guint *sorted_displays;
> +
> +    g_return_if_fail(displays != NULL);
> +
> +    if (ndisplays == 0)
> +        return;
> +
> +    sorted_displays = g_new0(guint, ndisplays);
> +    for (i = 0; i < ndisplays; i++)
> +        sorted_displays[i] = i;
> +    g_qsort_with_data(sorted_displays, ndisplays, sizeof(guint), displays_cmp, displays);
> +
> +    /* adjust monitor positions so that there's no gaps or overlap between
> +     * monitors */
> +    for (i = 0; i < ndisplays; i++) {
> +        guint nth = sorted_displays[i];
> +        g_assert(nth < ndisplays);
> +        GdkRectangle *rect = &displays[nth];
> +        rect->x = x;
> +        rect->y = 0;
> +        x += rect->width;
> +    }
> +    g_free(sorted_displays);
> +}
> +
>  /*
>   * Local variables:
>   *  c-indent-level: 4
> diff --git a/src/virt-viewer-util.h b/src/virt-viewer-util.h
> index 287f9bd..3973dde 100644
> --- a/src/virt-viewer-util.h
> +++ b/src/virt-viewer-util.h
> @@ -55,6 +55,9 @@ gulong virt_viewer_signal_connect_object(gpointer instance,
>  gchar* spice_hotkey_to_gtk_accelerator(const gchar *key);
>  gint virt_viewer_compare_version(const gchar *s1, const gchar *s2);
>  
> +/* monitor alignment */
> +void virt_viewer_align_monitors_linear(GdkRectangle *displays, guint ndisplays);
> +
>  #endif
>  
>  /*
> -- 
> 1.9.3
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20141022/1d90eee2/attachment.sig>


More information about the virt-tools-list mailing list