From cd39202f23b8ac9f712728b1a0a23c8b06b31ef0 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 19 Apr 2007 15:25:34 +0000 Subject: [PATCH] Add API for getting properties of the ClutterBackend Add functions to retrieve some of the properties of the screen used by the backend, like its dimensions (also physical, in millimeters); the number of screens. Also add setters and getters for the double click time (in milliseconds) and distance. --- clutter/clutter-backend.c | 82 +++++++++++++++++++++++++++++++ clutter/clutter-backend.h | 29 +++++++++-- clutter/glx/clutter-backend-glx.c | 33 ++++++++----- clutter/glx/clutter-backend-glx.h | 3 +- 4 files changed, 128 insertions(+), 19 deletions(-) diff --git a/clutter/clutter-backend.c b/clutter/clutter-backend.c index 55fa711fe..5f608a74b 100644 --- a/clutter/clutter-backend.c +++ b/clutter/clutter-backend.c @@ -224,3 +224,85 @@ clutter_backend_put_event (ClutterBackend *backend, _clutter_event_queue_push (backend, clutter_event_copy (event)); } + +gint +clutter_backend_get_width (ClutterBackend *backend) +{ + g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1); + + return backend->res_width; +} + +gint +clutter_backend_get_height (ClutterBackend *backend) +{ + g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1); + + return backend->res_height; +} + +gint +clutter_backend_get_width_mm (ClutterBackend *backend) +{ + g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1); + + return backend->mm_width; +} + +gint +clutter_backend_get_height_mm (ClutterBackend *backend) +{ + g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1); + + return backend->mm_height; +} + +gint +clutter_backend_get_screen_number (ClutterBackend *backend) +{ + g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1); + + return backend->screen_n; +} + +gdouble +clutter_backend_get_resolution (ClutterBackend *backend) +{ + g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), 0.0); + + return (gdouble) backend->res_width / (gdouble) backend->res_height; +} + +void +clutter_backend_set_double_click_time (ClutterBackend *backend, + guint msec) +{ + g_return_if_fail (CLUTTER_IS_BACKEND (backend)); + + backend->double_click_time = msec; +} + +guint +clutter_backend_get_double_click_time (ClutterBackend *backend) +{ + g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), 0); + + return backend->double_click_time; +} + +void +clutter_backend_set_double_click_distance (ClutterBackend *backend, + guint distance) +{ + g_return_if_fail (CLUTTER_IS_BACKEND (backend)); + + backend->double_click_distance = distance; +} + +guint +clutter_backend_get_double_click_distance (ClutterBackend *backend) +{ + g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), 0); + + return backend->double_click_distance; +} diff --git a/clutter/clutter-backend.h b/clutter/clutter-backend.h index 0bae88bb1..57ab438bf 100644 --- a/clutter/clutter-backend.h +++ b/clutter/clutter-backend.h @@ -47,6 +47,12 @@ struct _ClutterBackend GObject parent_instance; /*< private >*/ + gint mm_width; + gint mm_height; + gint res_width; + gint res_height; + + gint screen_n; /* events queue: every backend must implement one */ GQueue *events_queue; @@ -81,14 +87,27 @@ struct _ClutterBackendClass GOptionGroup *group); }; -GType clutter_backend_get_type (void) G_GNUC_CONST; +GType clutter_backend_get_type (void) G_GNUC_CONST; ClutterBackend *clutter_get_default_backend (void); -ClutterEvent * clutter_backend_get_event (ClutterBackend *backend); -ClutterEvent * clutter_backend_peek_event (ClutterBackend *backend); -void clutter_backend_put_event (ClutterBackend *backend, - ClutterEvent *event); +ClutterEvent *clutter_backend_get_event (ClutterBackend *backend); +ClutterEvent *clutter_backend_peek_event (ClutterBackend *backend); +void clutter_backend_put_event (ClutterBackend *backend, + ClutterEvent *event); + +gint clutter_backend_get_width (ClutterBackend *backend); +gint clutter_backend_get_height (ClutterBackend *backend); +gint clutter_backend_get_width_mm (ClutterBackend *backend); +gint clutter_backend_get_height_mm (ClutterBackend *backend); +gint clutter_backend_get_screen_number (ClutterBackend *backend); + +void clutter_backend_set_double_click_time (ClutterBackend *backend, + guint msec); +guint clutter_backend_get_double_click_time (ClutterBackend *backend); +void clutter_backend_set_double_click_distance (ClutterBackend *backend, + guint distance); +guint clutter_backend_get_double_click_distance (ClutterBackend *backend); G_END_DECLS diff --git a/clutter/glx/clutter-backend-glx.c b/clutter/glx/clutter-backend-glx.c index 685fa2ec2..1e9c9ae04 100644 --- a/clutter/glx/clutter-backend-glx.c +++ b/clutter/glx/clutter-backend-glx.c @@ -95,19 +95,24 @@ clutter_backend_glx_post_parse (ClutterBackend *backend, CLUTTER_NOTE (MISC, "Getting the X screen"); if (clutter_screen == 0) - backend_glx->xscreen = DefaultScreen (backend_glx->xdpy); + backend_glx->xscreen = DefaultScreenOfDisplay (backend_glx->xdpy); else - { - Screen *xscreen; - - xscreen = ScreenOfDisplay (backend_glx->xdpy, clutter_screen); - backend_glx->xscreen = XScreenNumberOfScreen (xscreen); - } + backend_glx->xscreen = ScreenOfDisplay (backend_glx->xdpy, + clutter_screen); + + backend_glx->xscreen_num = XScreenNumberOfScreen (backend_glx->xscreen); backend_glx->xwin_root = RootWindow (backend_glx->xdpy, - backend_glx->xscreen); + backend_glx->xscreen_num); backend_glx->display_name = g_strdup (clutter_display_name); + + /* generic backend properties */ + backend->res_width = WidthOfScreen (backend_glx->xscreen); + backend->res_height = HeightOfScreen (backend_glx->xscreen); + backend->mm_width = WidthMMOfScreen (backend_glx->xscreen); + backend->mm_height = HeightMMOfScreen (backend_glx->xscreen); + backend->screen_n = ScreenCount (backend_glx->xdpy); } g_free (clutter_display_name); @@ -115,7 +120,7 @@ clutter_backend_glx_post_parse (ClutterBackend *backend, CLUTTER_NOTE (MISC, "X Display `%s' [%p] opened (screen:%d, root:%u)", backend_glx->display_name, backend_glx->xdpy, - backend_glx->xscreen, + backend_glx->xscreen_num, (unsigned int) backend_glx->xwin_root); return TRUE; @@ -146,7 +151,7 @@ clutter_backend_glx_init_stage (ClutterBackend *backend, stage_glx = CLUTTER_STAGE_GLX (stage); stage_glx->xdpy = backend_glx->xdpy; stage_glx->xwin_root = backend_glx->xwin_root; - stage_glx->xscreen = backend_glx->xscreen; + stage_glx->xscreen = backend_glx->xscreen_num; CLUTTER_NOTE (MISC, "GLX stage created (display:%p, screen:%d, root:%u)", stage_glx->xdpy, @@ -302,6 +307,10 @@ clutter_backend_glx_init (ClutterBackendGlx *backend_glx) backend->button_x[0] = backend->button_x[1] = 0; backend->button_y[0] = backend->button_y[1] = 0; + backend->res_width = backend->res_height = -1; + backend->mm_width = backend->mm_height = -1; + backend->screen_n = 0; + /* FIXME - find a way to set this stuff from XSettings */ backend->double_click_time = 250; backend->double_click_distance = 5; @@ -392,7 +401,7 @@ clutter_glx_get_default_screen (void) return -1; } - return backend_singleton->xscreen; + return backend_singleton->xscreen_num; } /** @@ -415,5 +424,3 @@ clutter_glx_get_root_window (void) return backend_singleton->xwin_root; } - - diff --git a/clutter/glx/clutter-backend-glx.h b/clutter/glx/clutter-backend-glx.h index f05ad6aba..6496d4bc8 100644 --- a/clutter/glx/clutter-backend-glx.h +++ b/clutter/glx/clutter-backend-glx.h @@ -48,7 +48,8 @@ struct _ClutterBackendGlx Display *xdpy; Window xwin_root; - int xscreen; + Screen *xscreen; + int xscreen_num; gchar *display_name; /* main stage singleton */