magnifier-main.c

Go to the documentation of this file.
00001 /*
00002  * AT-SPI - Assistive Technology Service Provider Interface
00003  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
00004  *
00005  * Copyright 2001 Sun Microsystems Inc.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public
00018  * License along with this library; if not, write to the
00019  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  */
00022 
00023 #include "config.h"
00024 #include "magnifier.h"
00025 #include "magnifier-private.h"
00026 #include "zoom-region.h"
00027 #include "gmag-graphical-server.h"
00028 #include "GNOME_Magnifier.h"
00029 
00030 #include <unistd.h>
00031 
00032 #include <string.h>
00033 #include <stdlib.h>
00034 #include <sys/time.h>
00035 
00036 #include <gdk/gdk.h>
00037 #include <gdk/gdkx.h>
00038 #include <gtk/gtk.h>
00039 
00040 #include <libbonobo.h>
00041 
00042 #define ENV_STRING_MAX_SIZE 128
00043 
00044 GNOME_Magnifier_ZoomRegion zoom_region;
00045 
00046 typedef struct {
00047         gchar    *target_display;
00048         gchar    *source_display;
00049         gchar    *cursor_set;
00050         gchar    *smoothing_type;
00051         gdouble   zoom_factor;
00052         gdouble   zoom_factor_x;
00053         gdouble   zoom_factor_y;
00054         gint      refresh_time;
00055         gint      mouse_poll_time;
00056         gint      cursor_size;
00057         gdouble   cursor_scale_factor;
00058         gint64    cursor_color;
00059         gboolean  vertical_split;
00060         gboolean  horizontal_split;
00061         gboolean  fullscreen;
00062         gboolean  mouse_follow;
00063         gboolean  invert_image;
00064         gboolean  no_initial_region;
00065         gint      timing_iterations;
00066         gboolean  timing_output;
00067         gint      timing_delta_x;
00068         gint      timing_delta_y;
00069         gint      timing_pan_rate;
00070         gboolean  smooth_scroll;
00071         gint      border_width;
00072         gint64    border_color;
00073         gboolean  test_pattern;
00074         gboolean  is_override_redirect;
00075         gboolean  ignore_damage;
00076 #ifdef HAVE_COMPOSITE
00077         gboolean   ignore_composite;
00078 #endif /* HAVE_COMPOSITE */
00079         gboolean  print_version;
00080         gboolean  hide_pointer;
00081         gboolean  show_crosswires;
00082 } MagnifierOptions;
00083 
00084 static MagnifierOptions global_options = { NULL,      /* target_display */
00085                                            NULL,      /* source_display */
00086                                            "default", /* cursor_set */
00087                                            "none",    /* smoothing_type */
00088                                            2.0,       /* zoom_factor */
00089                                            0.0,       /* zoom_factor_x */
00090                                            0.0,       /* zoom_factor_y */
00091                                            500,       /* refresh_time */
00092                                            50,        /* mouse_poll_time */
00093                                            0,         /* cursor_size */
00094                                            0.0F,      /* cursor_scale_factor */
00095                                            0xFF000000,/* cursor_color */
00096                                            0,         /* vertical_split */
00097                                            0,         /* horizontal_split */
00098                                            0,         /* fullscreen */
00099                                            0,         /* mouse_follow */
00100                                            0,         /* invert_image */
00101                                            0,         /* no_initial_region */
00102                                            0,         /* timing_iterations */
00103                                            0,         /* timing_output */
00104                                            10,        /* timing_delta_x */
00105                                            10,        /* timing_delat_y */
00106                                            0,         /* timing_pan_rate */
00107                                            1,         /* smooth_scroll */
00108                                            0,         /* border_width */
00109                                            0,         /* border_color */
00110                                            0,         /* test_pattern */
00111                                            0,         /* is_override_redirect*/
00112                                            0          /* ignore_damage */
00113 #ifdef HAVE_COMPOSITE
00114                                            ,0         /* ignore_composite */
00115 #endif /* HAVE_COMPOSITE */
00116                                            ,0,        /* print_version */
00117                                            0,         /* hide_pointer */
00118                                            0          /* show_crosswires */ 
00119                                          };
00120 
00121 static GOptionEntry magnifier_options [] = {
00122         {"target-display", 't', 0, G_OPTION_ARG_STRING, &global_options.target_display, "specify display on which to show magnified view", NULL},
00123         {"source-display", 's', 0, G_OPTION_ARG_STRING, &global_options.source_display, "specify display to magnify", NULL},
00124         {"cursor-set", 0, 0, G_OPTION_ARG_STRING, &global_options.cursor_set, "cursor set to use in target display", NULL},
00125         {"cursor-size", 0, 0, G_OPTION_ARG_INT, &global_options.cursor_size, "cursor size to use (overrides cursor-scale-factor)", NULL},
00126         {"cursor-scale-factor", 0, 0, G_OPTION_ARG_DOUBLE, &global_options.cursor_scale_factor, "cursor scale factor", NULL},
00127         {"cursor-color", 0, 0, G_OPTION_ARG_INT64, &global_options.cursor_color, "cursor color (applied to \'black\' pixels)", NULL},
00128         {"vertical", 'v', 0, G_OPTION_ARG_NONE, &global_options.vertical_split, "split screen vertically (if target display = source display)", NULL},
00129         {"horizontal", 'h', 0, G_OPTION_ARG_NONE, &global_options.horizontal_split, "split screen horizontally (if target display = source display)", NULL},
00130         {"mouse-follow", 'm', 0, G_OPTION_ARG_NONE, &global_options.mouse_follow, "track mouse movements", NULL},
00131         {"refresh-time", 'r', 0, G_OPTION_ARG_INT, &global_options.refresh_time, "minimum refresh time for idle, in ms", NULL},
00132         {"mouse-latency", 0, 0, G_OPTION_ARG_INT, &global_options.mouse_poll_time, "maximum mouse latency time, in ms", NULL},
00133         {"zoom-factor", 'z', 0, G_OPTION_ARG_DOUBLE, &global_options.zoom_factor, "zoom (scale) factor used to magnify source display", NULL}, 
00134         {"invert-image", 'i', 0, G_OPTION_ARG_NONE, &global_options.invert_image, "invert the image colormap", NULL}, 
00135         {"no-initial-region", 0, 0, G_OPTION_ARG_NONE, &global_options.no_initial_region, "don't create an initial zoom region", NULL},
00136         {"timing-iterations", 0, 0, G_OPTION_ARG_INT, &global_options.timing_iterations, "iterations to run timing benchmark test (0=continuous)", NULL},
00137         {"timing-output", 0, 0, G_OPTION_ARG_NONE, &global_options.timing_output, "display performance ouput", NULL},
00138         {"timing-pan-rate", 0, 0, G_OPTION_ARG_INT, &global_options.timing_pan_rate, "timing pan rate in lines per frame", NULL},
00139         {"timing-delta-x", 0, 0, G_OPTION_ARG_INT, &global_options.timing_delta_x, "pixels to pan in x-dimension each frame in timing update test", NULL},
00140         {"timing-delta-y", 0, 0, G_OPTION_ARG_INT, &global_options.timing_delta_y, "pixels to pan in y-dimension each frame in timing update test", NULL},
00141         {"smoothing-type", 0, 0, G_OPTION_ARG_STRING, &global_options.smoothing_type, "image smoothing algorithm to apply (bilinear-interpolation | none)", NULL},
00142         {"fullscreen", 'f', 0, G_OPTION_ARG_NONE, &global_options.fullscreen, "fullscreen magnification, covers entire target display [REQUIRES --source-display and --target-display]", NULL},
00143         {"smooth-scrolling", 0, 0, G_OPTION_ARG_NONE, &global_options.smooth_scroll, "use smooth scrolling", NULL},
00144         {"border-size", 'b', 0, G_OPTION_ARG_INT, &global_options.border_width, "width of border", NULL},
00145         {"border-color", 'c', 0, G_OPTION_ARG_INT64, &global_options.border_color, "border color specified as (A)RGB 23-bit value, Alpha-MSB", NULL},
00146         {"hide-pointer", 0, 0, G_OPTION_ARG_NONE, &global_options.hide_pointer, "hide magnifier pointer when passed", NULL},
00147         {"show-crosswires", 0, 0, G_OPTION_ARG_NONE, &global_options.show_crosswires, "show crosswires when passed", NULL},
00148         {"use-test-pattern", 0, 0, G_OPTION_ARG_NONE, &global_options.test_pattern, "use test pattern as source", NULL},
00149         {"override-redirect", 0, 0, G_OPTION_ARG_NONE, &global_options.is_override_redirect, "make the magnifier window totally unmanaged by the window manager", NULL},
00150         {"ignore-damage", 0, 0, G_OPTION_ARG_NONE, &global_options.ignore_damage, "ignore the X server DAMAGE extension, if present", NULL},
00151 #ifdef HAVE_COMPOSITE
00152         {"ignore-composite", 0, 0, G_OPTION_ARG_NONE, &global_options.ignore_composite, "ignore the X server COMPOSITE extension, if present", NULL},
00153 #endif /* HAVE_COMPOSITE */
00154         {"version", 0, 0, G_OPTION_ARG_NONE, &global_options.print_version, "print version", NULL},
00155         {NULL}
00156 };
00157 
00158 static void
00159 init_rect_bounds (GNOME_Magnifier_RectBounds *bounds,
00160                   long x1, long y1, long x2, long y2)
00161 {
00162         bounds->x1 = x1;
00163         bounds->y1 = y1;
00164         bounds->x2 = x2;
00165         bounds->y2 = y2;
00166 }
00167 
00168 static int target_width, target_height;
00169 
00170 static int
00171 magnifier_main_test_image (gpointer data)
00172 {
00173         static long timing_counter = 0;
00174         static int timing_x_pos = 0;
00175         static int timing_y_pos = 0;
00176         static int x_direction = 1;
00177         static int y_direction = 1;
00178         Magnifier *magnifier = (Magnifier *) data;
00179         GNOME_Magnifier_ZoomRegionList *zoom_regions;
00180         Bonobo_PropertyBag properties;
00181         CORBA_Environment ev;
00182         GNOME_Magnifier_RectBounds roi;
00183         int x_roi, y_roi;
00184         
00185         /* Only iterate the number of times specified */
00186         if (global_options.timing_iterations > 0) {
00187                 if (timing_counter > global_options.timing_iterations) {
00188                         CORBA_exception_init (&ev);
00189                         properties = GNOME_Magnifier_ZoomRegion_getProperties (zoom_region, &ev);
00190                         if (BONOBO_EX (&ev))
00191                                 fprintf (stderr, "EXCEPTION\n");
00192 
00193                         bonobo_pbclient_set_boolean (properties, "exit-magnifier",
00194                                        TRUE, &ev);
00195                 }
00196         }
00197 
00198         CORBA_exception_init (&ev);
00199 
00200         x_roi  = global_options.timing_delta_x * timing_x_pos;
00201         roi.x1 = x_roi;
00202         roi.x2 = (target_width / global_options.zoom_factor) + roi.x1;
00203         x_roi  = global_options.timing_delta_x * (timing_x_pos + x_direction);
00204 
00205         /* Determine if magnifier hit an edge and should reverse direction */
00206         if (x_roi + (target_width / global_options.zoom_factor) > target_width)
00207                 x_direction = -1;
00208         else if (x_roi < 0)
00209                 x_direction = 1;
00210 
00211         timing_x_pos += x_direction;
00212 
00213         y_roi = global_options.timing_delta_y * timing_y_pos;
00214 
00215         /* Calculate size of screen not covered by magnifier */
00216         if (global_options.horizontal_split)
00217                 roi.y1 = y_roi + target_height;
00218         else
00219                 roi.y1 = y_roi;
00220         roi.y2 = (target_height / global_options.zoom_factor) + roi.y1;
00221 
00222         y_roi = global_options.timing_delta_y * (timing_y_pos + y_direction);
00223 
00224         /* The counter is increased each time the y-direction changes */
00225         if (y_roi + (target_height / global_options.zoom_factor) >
00226             target_height) {
00227                 timing_counter++;
00228                 y_direction = -1;
00229         }
00230         else if (y_roi < 0) {
00231                 timing_counter++;
00232                 y_direction = 1;
00233         }
00234 
00235         timing_y_pos += y_direction;
00236 
00237         if (!IS_MAGNIFIER (magnifier))
00238                 return FALSE;
00239 
00240         magnifier->priv->cursor_x = (roi.x2 + roi.x1) / 2;
00241         magnifier->priv->cursor_y = (roi.y2 + roi.y1) / 2;
00242 
00243         zoom_regions =
00244                 GNOME_Magnifier_Magnifier_getZoomRegions (
00245                         BONOBO_OBJREF (magnifier),
00246                         &ev);
00247 
00248         if (zoom_regions && (zoom_regions->_length > 0)) {
00249 
00250                 GNOME_Magnifier_ZoomRegion_setROI (
00251                         zoom_regions->_buffer[0], &roi, &ev);
00252         }
00253 
00254         return TRUE;
00255 }
00256 
00257 static int last_x = 0, last_y = 0;
00258 
00259 static int
00260 magnifier_main_pan_image (gpointer data)
00261 {
00262   Magnifier *magnifier = (Magnifier *) data;
00263   GNOME_Magnifier_ZoomRegionList *zoom_regions;
00264   GNOME_Magnifier_ZoomRegion zoom_region;
00265   CORBA_Environment ev;
00266   GNOME_Magnifier_RectBounds roi;
00267   int mouse_x_return, mouse_y_return;
00268   int w, h;
00269   GdkModifierType mask_return;
00270 
00271   CORBA_exception_init (&ev);
00272 
00273   if (global_options.mouse_follow && IS_MAGNIFIER (magnifier))
00274   {
00275           gdk_window_get_pointer (
00276                   magnifier_get_root (magnifier),
00277                   &mouse_x_return,
00278                   &mouse_y_return,
00279                   &mask_return);
00280           
00281           if (last_x != mouse_x_return || last_y != mouse_y_return)
00282           {
00283                   last_x = mouse_x_return;
00284                   last_y = mouse_y_return;
00285                   w = (magnifier->target_bounds.x2 - magnifier->target_bounds.x1);
00286                   h = (magnifier->target_bounds.y2 - magnifier->target_bounds.y1);
00287                   roi.x1 = mouse_x_return;
00288                   roi.y1 = mouse_y_return;
00289                   roi.x2 = roi.x1 + 1;
00290                   roi.y2 = roi.y1 + 1;
00291                   
00292                   zoom_regions =
00293                           GNOME_Magnifier_Magnifier_getZoomRegions (
00294                                   BONOBO_OBJREF (magnifier),
00295                                   &ev);
00296                   if (zoom_regions && (zoom_regions->_length > 0))
00297                   {
00298                           int i;
00299                           for (i = 0; i < zoom_regions->_length; ++i)
00300                           {
00301                                   /* fprintf (stderr, "panning region %d\n", i);*/
00302                                   zoom_region =
00303                                           CORBA_Object_duplicate (
00304                                                   ( (CORBA_Object *)
00305                                                     (zoom_regions->_buffer))[i], &ev);
00306                                   if (zoom_region != CORBA_OBJECT_NIL) {
00307                                           GNOME_Magnifier_ZoomRegion_setROI (zoom_region,
00308                                                                              &roi,
00309                                                                              &ev);
00310                                   } else fprintf (stderr, "nil region!\n");
00311                           }
00312                   }
00313           }
00314           return TRUE;
00315   }
00316   
00317   return FALSE;
00318 }
00319 
00320 static int
00321 magnifier_main_refresh_all (gpointer data)
00322 {
00323         int i;
00324         Magnifier *magnifier = data;
00325         CORBA_any *dirty_bounds_any;
00326         CORBA_Environment ev;
00327         Bonobo_PropertyBag properties;
00328         GNOME_Magnifier_RectBounds *dirty_bounds;
00329         GNOME_Magnifier_ZoomRegionList *regions;
00330         
00331         CORBA_exception_init (&ev);
00332 
00333         if (!IS_MAGNIFIER (magnifier))
00334                 return FALSE;
00335         
00336         regions = GNOME_Magnifier_Magnifier_getZoomRegions (
00337                 BONOBO_OBJREF (magnifier),
00338                 &ev);
00339 
00340 #ifdef DEBUG_REFRESH
00341         fprintf (stderr, "refreshing %d regions\n", regions->_length);
00342 #endif
00343 
00344         properties = GNOME_Magnifier_Magnifier_getProperties (BONOBO_OBJREF (magnifier), &ev);
00345 
00346         dirty_bounds_any = Bonobo_PropertyBag_getValue (properties, "source-display-bounds", &ev);
00347         if (BONOBO_EX (&ev)) {
00348                 g_warning ("Error getting source-display-bounds");
00349                 bonobo_main_quit ();
00350                 return FALSE;
00351         }
00352 
00353         dirty_bounds = (GNOME_Magnifier_RectBounds *) dirty_bounds_any->_value;
00354 
00355           fprintf (stderr, "region to update: %d %d %d %d\n",
00356                  dirty_bounds->x1, dirty_bounds->y1, dirty_bounds->x2, dirty_bounds->y2);
00357 
00358         for (i = 0; i < regions->_length; ++i)
00359                 GNOME_Magnifier_ZoomRegion_markDirty (
00360                         regions->_buffer [i], dirty_bounds, &ev);
00361 
00362         bonobo_object_release_unref (properties, NULL);
00363 
00364         return TRUE;
00365 }
00366 
00367 int
00368 main (int argc, char** argv)
00369 {
00370   GOptionContext *context;
00371   GNOME_Magnifier_RectBounds *roi = GNOME_Magnifier_RectBounds__alloc();
00372   GNOME_Magnifier_RectBounds *viewport = GNOME_Magnifier_RectBounds__alloc();
00373   CORBA_any *viewport_any;
00374   int x = 0, y = 0, src_width, src_height;
00375   guint pan_handle = 0, refresh_handle = 0;
00376   CORBA_Environment ev;
00377   Bonobo_PropertyBag properties;
00378   
00379   Magnifier *magnifier;
00380   
00381   if (!bonobo_init (&argc, argv)) {
00382     g_error ("Could not initialize Bonobo");
00383   }
00384   CORBA_exception_init (&ev);
00385   
00386   context = g_option_context_new ("- a screen magnifier for Gnome");
00387   g_option_context_set_description (context, "Report bugs to http://bugzilla.gnome.org\n");
00388   g_option_context_add_main_entries (context, magnifier_options, "main options");
00389   g_option_context_set_ignore_unknown_options (context, TRUE);
00390   g_option_context_parse(context, &argc, &argv, NULL);
00391   g_option_context_free(context);
00392 
00393   if (global_options.print_version) {
00394           g_print ("%s\n", VERSION);
00395           return 0;
00396   }
00397 
00403   if (global_options.target_display) {
00404           gchar *string;
00405           string = g_strconcat ("DISPLAY=", global_options.target_display, NULL);
00406           putenv (string);
00407   } else {
00408                   global_options.target_display = g_getenv ("DISPLAY");
00409                   if (!global_options.target_display) {
00410                           fprintf (stderr, _("Can't open display: DISPLAY is not set"));
00411                           exit (1);
00412                   }
00413   }  
00414 
00415   if (!global_options.source_display) {
00416                   global_options.source_display = global_options.target_display;
00417   }
00418 
00419   if (global_options.timing_pan_rate && global_options.timing_iterations == 0)
00420   {
00421     g_error ("Must specify timing_iterations when running pan test");
00422   }
00423 
00424   /* FIXME */
00425   gtk_init (&argc, &argv);
00426 
00427   if (global_options.ignore_damage)
00428   {
00429       g_setenv ("MAGNIFIER_IGNORE_DAMAGE", "1", TRUE);
00430   }
00431 #ifdef HAVE_COMPOSITE
00432   if (global_options.ignore_composite)
00433           g_setenv ("MAGNIFIER_IGNORE_COMPOSITE", "1", TRUE);
00434 #endif /* HAVE_COMPOSITE */
00435 
00436   magnifier = magnifier_new (global_options.is_override_redirect);
00437   
00438   properties = GNOME_Magnifier_Magnifier_getProperties (
00439           BONOBO_OBJREF (magnifier), &ev);
00440   if (ev._major != CORBA_NO_EXCEPTION) fprintf (stderr, "EXCEPTION\n");
00441   
00442   if (global_options.target_display)
00443           bonobo_pbclient_set_string (properties, "target-display-screen",
00444                                       global_options.target_display, NULL);
00445 
00446   if (global_options.source_display)
00447           bonobo_pbclient_set_string (properties, "source-display-screen",
00448                                       global_options.source_display, NULL);
00449 
00450   if (global_options.cursor_set)
00451           bonobo_pbclient_set_string (properties, "cursor-set",
00452                                       global_options.cursor_set, NULL);
00453 
00454   if (global_options.cursor_size)
00455           bonobo_pbclient_set_long (properties, "cursor-size",
00456                                     global_options.cursor_size, NULL);
00457 
00458   else if (global_options.cursor_scale_factor != 0.0F)
00459           bonobo_pbclient_set_float (properties, "cursor-scale-factor",
00460                                      global_options.cursor_scale_factor, NULL);
00461   else 
00462           bonobo_pbclient_set_float (properties, "cursor-scale-factor",
00463                                      global_options.zoom_factor, NULL);
00464 
00465   if (global_options.cursor_color)
00466           bonobo_pbclient_set_ulong (properties, "cursor-color",
00467                                      global_options.cursor_color, 
00468                                      NULL);
00469 
00470   if (!global_options.show_crosswires)
00471           bonobo_pbclient_set_long (properties, "crosswire-size", 0, NULL);
00472 
00473   src_width = gdk_screen_get_width (gdk_display_get_screen (
00474                                             magnifier->source_display,
00475                                             magnifier->source_screen_num));
00476   src_height = gdk_screen_get_height (gdk_display_get_screen (
00477                                               magnifier->source_display,
00478                                               magnifier->source_screen_num));
00479 
00480   target_width = gdk_screen_get_width (gdk_display_get_screen (
00481                                                magnifier->target_display,
00482                                                magnifier->target_screen_num));
00483   target_height = gdk_screen_get_height (
00484           gdk_display_get_screen (magnifier->target_display,
00485                                   magnifier->target_screen_num));
00486 
00487   if (global_options.vertical_split) {
00488           target_width /= 2;
00489           x = target_width;
00490   }
00491   if (global_options.horizontal_split) {
00492           target_height /= 2;
00493           y = target_height;
00494   }
00495 
00496   fprintf (stderr, "initial viewport %d %d\n", (int) target_width,
00497            (int) target_height);
00498 
00499   
00500   if (global_options.vertical_split || global_options.horizontal_split ||
00501       global_options.fullscreen) {
00502           init_rect_bounds (viewport, x, y, x + target_width,
00503                             y + target_height);
00504           viewport_any = bonobo_arg_new_from (TC_GNOME_Magnifier_RectBounds,
00505                                               viewport);
00506   
00507           bonobo_pbclient_set_value (properties, "target-display-bounds",
00508                                      viewport_any, &ev);
00509           bonobo_arg_release (viewport_any);
00510   }
00511 
00512   if (global_options.vertical_split || global_options.horizontal_split) 
00513   {
00514 #ifdef HAVE_COMPOSITE
00515           if (!g_getenv ("MAGNIFIER_IGNORE_COMPOSITE"))
00516                   init_rect_bounds (viewport, 0, 0,
00517                                     src_width, src_height);
00518           else
00519 #endif /* HAVE_COMPOSITE */
00520                   init_rect_bounds (viewport, 0, 0,
00521                                     src_width-x, src_height-y);
00522       viewport_any = bonobo_arg_new_from (TC_GNOME_Magnifier_RectBounds,
00523                                           viewport);
00524       bonobo_pbclient_set_value (properties, "source-display-bounds",
00525                                  viewport_any,
00526                                  &ev);
00527 
00528       bonobo_arg_release (viewport_any);
00529   } else if (global_options.fullscreen) {
00530           init_rect_bounds (viewport, 0, 0, src_width, src_height);
00531           viewport_any = bonobo_arg_new_from (TC_GNOME_Magnifier_RectBounds,
00532                                               viewport);
00533           bonobo_pbclient_set_value (properties, "source-display-bounds",
00534                                      viewport_any,
00535                                      &ev);
00536           bonobo_arg_release (viewport_any);
00537   }
00538 
00539   bonobo_object_release_unref (properties, NULL);
00540   properties = NULL;
00541 
00542   if (global_options.vertical_split ||
00543       global_options.horizontal_split ||
00544       global_options.fullscreen)
00545   {
00546           int scroll_policy;
00547           
00548           init_rect_bounds (roi, 0, 0,
00549                             target_width / global_options.zoom_factor,
00550                             target_height / global_options.zoom_factor);
00551           init_rect_bounds (viewport, 0, 0, target_width, target_height);
00552           zoom_region =
00553                   GNOME_Magnifier_Magnifier_createZoomRegion (
00554                           BONOBO_OBJREF (magnifier),
00555                           global_options.zoom_factor,
00556                           global_options.zoom_factor,
00557                           roi,
00558                           viewport,
00559                           &ev);
00560           
00561           properties = GNOME_Magnifier_ZoomRegion_getProperties (zoom_region, &ev);
00562           if (BONOBO_EX (&ev))
00563                   fprintf (stderr, "EXCEPTION\n");
00564 
00565           scroll_policy = global_options.smooth_scroll ?
00566                   GNOME_Magnifier_ZoomRegion_SCROLL_SMOOTHEST :
00567                   GNOME_Magnifier_ZoomRegion_SCROLL_FASTEST;
00568 
00569           bonobo_pbclient_set_long (properties, "timing-iterations",
00570                                        global_options.timing_iterations, &ev);
00571           bonobo_pbclient_set_boolean (properties, "timing-output",
00572                                        global_options.timing_output, &ev);
00573           bonobo_pbclient_set_long (properties, "timing-pan-rate",
00574                                        global_options.timing_pan_rate, &ev);
00575           bonobo_pbclient_set_long    (properties, "border-size",
00576                                        global_options.border_width, &ev);
00577           bonobo_pbclient_set_long    (properties, "border-color",
00578                                        global_options.border_color, &ev);
00579           bonobo_pbclient_set_short   (properties, "smooth-scroll-policy",
00580                                        (short) scroll_policy, &ev);
00581           bonobo_pbclient_set_boolean (properties, "use-test-pattern",
00582                                        global_options.test_pattern, &ev);
00583           bonobo_pbclient_set_boolean (properties, "draw-cursor",
00584                                        !global_options.hide_pointer, &ev);
00585 
00586           if (strcmp (global_options.smoothing_type, "none"))
00587                   bonobo_pbclient_set_string (properties, "smoothing-type",
00588                                               global_options.smoothing_type, &ev);
00589 
00590           if (global_options.invert_image)
00591                   bonobo_pbclient_set_boolean (properties, "inverse-video",
00592                                                global_options.invert_image, NULL);
00593 
00594           GNOME_Magnifier_Magnifier_addZoomRegion (
00595                   BONOBO_OBJREF (magnifier),
00596                   zoom_region,
00597                   &ev);
00598 
00599           bonobo_object_release_unref (properties, &ev);
00600           properties = NULL;
00601   }
00602 
00603   if (global_options.timing_pan_rate)
00604   {
00605           GNOME_Magnifier_ZoomRegionList *zoom_regions;
00606           GNOME_Magnifier_RectBounds roi;
00607           roi.x1 = 100;
00608           roi.x2 = 100 + (target_width / global_options.zoom_factor);
00609           roi.y1 = 0;
00610           roi.y2 = target_height / global_options.zoom_factor;
00611           
00612           zoom_regions = GNOME_Magnifier_Magnifier_getZoomRegions (
00613                   BONOBO_OBJREF (magnifier), &ev);
00614           
00615           if (zoom_regions && (zoom_regions->_length > 0))
00616           {
00617                   GNOME_Magnifier_ZoomRegion_setROI (
00618                           zoom_regions->_buffer[0], &roi, &ev);
00619           }
00620   }
00621   else if (global_options.timing_iterations)
00622   {
00623           refresh_handle = g_timeout_add (global_options.refresh_time,
00624                                           magnifier_main_test_image,
00625                                           magnifier);
00626   }
00627   else
00628   {
00629           if (global_options.ignore_damage ||
00630               !gmag_gs_source_has_damage_extension (magnifier)) 
00631           {
00632                   refresh_handle = g_timeout_add (
00633                           global_options.refresh_time,
00634                           magnifier_main_refresh_all, magnifier);
00635           }
00636           
00637           pan_handle = g_timeout_add (
00638                   global_options.mouse_poll_time,
00639                   magnifier_main_pan_image, magnifier);
00640   }
00641   
00642   bonobo_main ();
00643   
00644   if (refresh_handle)
00645           g_source_remove (refresh_handle);
00646   
00647   if (pan_handle)
00648           g_source_remove (pan_handle);
00649 
00650   return 0;
00651 }
Generated on Sat Jun 19 11:24:41 2010 for gnome-mag by  doxygen 1.6.3