2 #include <gdk/gdkwindow.h>
7 #define ENV_STRING_MAX_SIZE 128
10 * Our parent GObject type
12 #define PARENT_TYPE BONOBO_OBJECT_TYPE
14 struct sockaddr_un mag_server = { AF_UNIX , "/tmp/magnifier_socket" };
27 gchar *target_display;
28 gchar *source_display;
38 int fast_cmap_convert;
42 static MagnifierOptions global_options = { ":0.0",
56 struct poptOption magnifier_options [] = {
57 {"target_display", 't', POPT_ARG_STRING, &global_options.target_display, 't', "specify display on which to show magnified view", NULL},
58 {"source_display", 's', POPT_ARG_STRING, &global_options.source_display, 's', "specify display to magnify", NULL},
59 {"vertical", 'v', POPT_ARG_NONE, &global_options.vertical_split, 'v', "split screen vertically (if target display = source display)", NULL},
60 {"horizontal", 'h', POPT_ARG_NONE, &global_options.horizontal_split, 'h', "split screen horizontally (if target display = source display)", NULL},
61 {"dual-head", 'd', POPT_ARG_NONE, &global_options.dual_head, 'd', "dual-head display mode (maps magnifier to second display)", NULL},
62 {"mouse follow", 'm', POPT_ARG_NONE, &global_options.mouse_follow, 'm', "track mouse movements", NULL},
63 {"refresh time", 'r', POPT_ARG_NONE, &global_options.min_refresh_time, 'r', "minimum refresh time for mouse follow and idle, in ms", NULL},
64 {"zoom (scale) factor", 'z', POPT_ARG_FLOAT, &global_options.zoom_factor, 'z', "zoom (scale) factor used to magnify source display", NULL},
65 /* {"invert image", 'i', POPT_ARG_NONE, &global_options.invert_image, 'i', "invert the image colormap", NULL}, */
66 {"fast-colormap-conversion", 'c', POPT_ARG_NONE, &global_options.fast_cmap_convert, 'c', "use faster colormap conversion algorithm (fails for 6 bit color)", NULL},
67 {"no-bonobo", '\0', POPT_ARG_NONE, &global_options.no_bonobo, '\0', "don't use bonobo for controls, use sockets", NULL},
68 {NULL, 0, 0, NULL, 0, 0}
73 static GtkWidget *window; /* TODO: clean up, with accessor func? */
76 magnifier_realize (GtkWidget *widget)
79 Atom wm_window_protocols[2];
80 static gboolean initialized = FALSE;
84 wm_window_protocols[0] = gdk_x11_get_xatom_by_name ("WM_DELETE_WINDOW");
85 wm_window_protocols[1] = gdk_x11_get_xatom_by_name ("_NET_WM_PING");
88 wm_hints.flags = InputHint;
89 wm_hints.input = False;
91 XSetWMHints (GDK_WINDOW_XDISPLAY (widget->window),
92 GDK_WINDOW_XWINDOW (widget->window), &wm_hints);
94 XSetWMProtocols (GDK_WINDOW_XDISPLAY (widget->window),
95 GDK_WINDOW_XWINDOW (widget->window), wm_window_protocols, 2);
104 static gboolean get_commands(GIOChannel* client,
105 GIOCondition condition,
110 memset(msg,0,MSG_LEN);
112 if((desc_client = accept(desc,(struct sockaddr*)&client_sockaddr,&size_client)) == -1){
113 perror("Could connect to client");exit(1);
116 read(desc_client,msg,sizeof(msg));
117 parse_message(msg, data);
122 int main (int argc, char** argv){
123 GIOChannel *mag_channel;
125 char env_string[ENV_STRING_MAX_SIZE];
127 /* TODO: finish replacing socket connection IPC with bonobo service. */
128 Magnifier *magnifier;
133 size_client = sizeof(client_sockaddr);
137 if (!bonobo_init (&argc, argv))
139 g_error ("Could not initialize Bonobo");
142 magnifier = magnifier_new (argc, argv);
144 magnifier->mag_data->follow_mouse =
145 global_options.mouse_follow;
146 magnifier->mag_data->color_inverted =
147 global_options.invert_image;
148 magnifier->mag_data->factor_x =
149 (int) global_options.zoom_factor;
150 magnifier->mag_data->factor_y =
151 (int) global_options.zoom_factor;
153 /* TODO: enable fractional magnifications ? */
154 if (global_options.target_display) {
155 snprintf (env_string, (size_t) (ENV_STRING_MAX_SIZE-1), "DISPLAY=%s", global_options.target_display);
158 gtk_init (&argc, &argv);
160 window = g_object_connect (gtk_widget_new (gtk_window_get_type (),
163 "type", GTK_WINDOW_TOPLEVEL,
164 "title", "magnifier",
166 "allow_shrink", FALSE,
169 "signal::realize", magnifier_realize, NULL,
170 "signal::destroy", magnifier_exit, NULL,
173 drawing_area = gtk_drawing_area_new();
174 gtk_container_add (GTK_CONTAINER (window),drawing_area);
175 gtk_widget_add_events(GTK_WIDGET(drawing_area),GDK_BUTTON_PRESS_MASK);
176 gtk_signal_connect (GTK_OBJECT (drawing_area),"expose_event",
177 GTK_SIGNAL_FUNC(expose_event),NULL);
180 if (global_options.no_bonobo) {
181 if((desc = socket(AF_UNIX,SOCK_STREAM,0)) == -1){
182 perror("Socket");exit(1);
184 unlink("/tmp/magnifier_socket");
186 if(bind(desc,(struct sockaddr*)&mag_server,sizeof(mag_server)) == -1){
187 perror("Bind");exit(1);
190 if(listen(desc,100) == -1){
191 perror("Listen");exit(1);
193 mag_channel = g_io_channel_unix_new(desc);
194 g_io_add_watch(mag_channel,
197 magnifier->mag_data);
201 /* init image information */
202 if (!global_options.source_display) global_options.source_display = gdk_get_display();
203 dpyname = global_options.source_display + (strlen(global_options.source_display) - 1);
204 screen_num = atoi(dpyname);
205 if (!global_options.target_display) {
206 if((screen_num == 0) && global_options.dual_head)
208 else if (global_options.dual_head)
210 global_options.target_display =
211 (char *) malloc (strlen (global_options.source_display));
212 strncpy (global_options.target_display,
213 global_options.source_display,
214 strlen(global_options.source_display)-2);
215 global_options.target_display[strlen(global_options.source_display)-2] = 0;
216 sprintf(global_options.target_display, "%s.%d",
217 global_options.target_display, screen_num);
220 printf("displays: source=%s; target=%s\n",
221 global_options.source_display,
222 global_options.target_display);
224 magnifier->mag_data->source_display = XOpenDisplay (global_options.source_display);
225 magnifier->mag_data->target_display = GDK_DISPLAY();
227 spi_image_root_window = RootWindow(magnifier->mag_data->source_display, screen_num);
228 gdk_pixbuf_xlib_init (magnifier->mag_data->source_display, screen_num);
229 image = gdk_pixbuf_new (GDK_COLORSPACE_RGB,FALSE, 8,
230 DisplayWidth (magnifier->mag_data->source_display,screen_num)/2,
231 DisplayHeight(magnifier->mag_data->source_display,screen_num)/2);
232 scaled_image = gdk_pixbuf_new (GDK_COLORSPACE_RGB,FALSE, 8,
233 DisplayWidth (magnifier->mag_data->target_display,screen_num),
234 DisplayHeight(magnifier->mag_data->target_display,screen_num));
235 if (global_options.vertical_split)
236 magnifier->mag_data->mag_width = DisplayWidth (magnifier->mag_data->target_display,screen_num)/2;
238 magnifier->mag_data->mag_width = DisplayWidth (magnifier->mag_data->target_display, screen_num);
239 if (global_options.horizontal_split)
240 magnifier->mag_data->mag_height = DisplayHeight (magnifier->mag_data->target_display,screen_num)/2;
241 else magnifier->mag_data->mag_height = DisplayHeight (magnifier->mag_data->target_display, screen_num);
242 gtk_window_set_decorated(GTK_WINDOW (window), FALSE);
243 gtk_widget_show_all (window);
245 gdk_window_move(window->window,
246 gdk_screen_width() - magnifier->mag_data->mag_width,
247 gdk_screen_height() - magnifier->mag_data->mag_height);
248 g_print ("setting size to %d by %d pixels\n",
249 magnifier->mag_data->mag_width, magnifier->mag_data->mag_height);
250 gdk_window_resize (window->window, magnifier->mag_data->mag_width, magnifier->mag_data->mag_height);
251 magnifier->mag_data->output_window = window;
252 if (global_options.fullscreen) gdk_window_stick (window->window);
253 gdk_window_set_functions(window->window, 0);
254 gdk_window_raise(window->window);
256 gtk_timeout_add(global_options.min_refresh_time, display_image, magnifier->mag_data);
258 obj_id = "OAFIID:Accessibility_Util_Magnifier:proto0.1";
260 if (! global_options.no_bonobo)
262 int ret = bonobo_activation_active_server_register (
263 obj_id, BONOBO_OBJREF (magnifier));
265 if (ret == Bonobo_ACTIVATION_REG_SUCCESS)
275 unlink("magnifier_socket");
280 impl_magnifier_fullscreen (PortableServer_Servant servant,
281 CORBA_Environment *ev)
283 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
284 magnifier->mag_data->mag_width = DisplayWidth (magnifier->mag_data->target_display, screen_num);
285 magnifier->mag_data->mag_height = DisplayHeight (magnifier->mag_data->target_display, screen_num);
289 impl_magnifier_set_extents (PortableServer_Servant servant,
294 CORBA_Environment *ev)
296 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
297 magnifier->mag_data->mag_width = x2 - x1;
298 magnifier->mag_data->mag_height = y2 - y1;
299 gdk_window_move(window->window, x1, y1);
303 impl_magnifier_set_follow_mouse (PortableServer_Servant servant,
304 const CORBA_boolean follow_mouse,
305 CORBA_Environment *ev)
307 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
308 magnifier->mag_data->follow_mouse = (int) follow_mouse;
312 impl_magnifier_set_contrast (PortableServer_Servant servant,
313 const CORBA_short contrast,
314 CORBA_Environment *ev)
316 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
317 magnifier->mag_data->contrast = (int) contrast;
321 impl_magnifier_set_source_display (PortableServer_Servant servant,
322 const CORBA_char *display,
323 CORBA_Environment *ev)
325 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
326 magnifier->mag_data->source_display =
327 XOpenDisplay (global_options.source_display);
331 impl_magnifier_set_target_display (PortableServer_Servant servant,
332 const CORBA_char *display,
333 CORBA_Environment *ev)
335 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
336 magnifier->mag_data->target_display = GDK_DISPLAY();
340 impl_magnifier_goto (PortableServer_Servant servant,
343 CORBA_Environment *ev)
345 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
346 magnifier->mag_data->center.x = (int) x;
347 magnifier->mag_data->center.y = (int) y;
351 impl_magnifier_set_roi (PortableServer_Servant servant,
352 const CORBA_short zoom_region,
357 CORBA_Environment *ev)
359 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
360 magnifier->mag_data->center.x = (int) ((x1 + x2)/2);
361 magnifier->mag_data->center.y = (int) ((y1 + y2)/2);
365 impl_magnifier_set_mag_factor (PortableServer_Servant servant,
366 const CORBA_short zoom_region,
367 const CORBA_float mag_factor_x,
368 const CORBA_float mag_factor_y,
369 CORBA_Environment *ev)
371 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
372 if (zoom_region == (CORBA_short) 0) /* TODO: fix for multi-zoom-regions */
374 magnifier->mag_data->factor_x = (float) mag_factor_x;
375 magnifier->mag_data->factor_y = (float) mag_factor_y;
380 impl_magnifier_mark_dirty (PortableServer_Servant servant,
381 const CORBA_short zoom_region,
382 CORBA_Environment *ev)
384 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
385 /* TODO: implement */
389 impl_magnifier_mark_unmanaged (PortableServer_Servant servant,
390 const CORBA_short zoom_region,
391 CORBA_Environment *ev)
393 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
394 /* TODO: implement */
398 impl_magnifier_create_zoom_region (PortableServer_Servant servant,
399 const CORBA_float zx,
400 const CORBA_float zy,
405 CORBA_Environment *ev)
407 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
412 impl_magnifier_get_zoom_region_params (PortableServer_Servant servant,
413 const CORBA_short zoom_region,
415 CORBA_float * zy, CORBA_long * x1,
416 CORBA_long * y1, CORBA_long * x2,
418 CORBA_Environment * ev)
420 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
421 if (zoom_region == (CORBA_short) 0)
423 *zx = magnifier->mag_data->factor_x;
424 *zy = magnifier->mag_data->factor_y;
427 *x2 = *x1 + magnifier->mag_data->mag_width;
428 *y2 = *y1 + magnifier->mag_data->mag_height;
431 else return CORBA_FALSE;
435 impl_magnifier_resize_zoom_region (PortableServer_Servant _servant,
436 const CORBA_short zoom_region,
437 const CORBA_long x1, const CORBA_long y1,
438 const CORBA_long x2, const CORBA_long y2,
439 CORBA_Environment * ev)
444 impl_magnifier_destroy_zoom_region (PortableServer_Servant _servant,
445 const CORBA_short zoom_region,
446 CORBA_Environment * ev)
451 impl_magnifier_clear_all_zoom_regions (PortableServer_Servant _servant,
452 CORBA_Environment * ev)
457 impl_magnifier_exit (PortableServer_Servant servant, CORBA_Environment *ev)
463 magnifier_class_init (MagnifierClass *klass)
465 GObjectClass * object_class = (GObjectClass *) klass;
466 POA_Accessibility_Magnifier__epv *epv = &klass->epv;
468 object_class->finalize = magnifier_finalize;
470 epv->_set_SourceDisplay = impl_magnifier_set_source_display;
471 epv->_set_TargetDisplay = impl_magnifier_set_target_display;
472 epv->setROI = impl_magnifier_set_roi;
473 epv->setMagFactor = impl_magnifier_set_mag_factor;
474 epv->markDirty = impl_magnifier_mark_dirty;
475 epv->markUnmanaged = impl_magnifier_mark_unmanaged;
476 epv->createZoomRegion = impl_magnifier_create_zoom_region;
477 epv->getZoomRegionParams = impl_magnifier_get_zoom_region_params;
478 epv->resizeZoomRegion = impl_magnifier_resize_zoom_region;
479 epv->destroyZoomRegion = impl_magnifier_destroy_zoom_region;
480 epv->clearAllZoomRegions = impl_magnifier_clear_all_zoom_regions;
481 epv->exit = impl_magnifier_exit;
485 magnifier_init (Magnifier *magnifier)
487 magnifier->mag_data = (MagnifierData *) g_new0 (MagnifierData, 1);
488 magnifier->mag_data->factor_x = 2;
489 magnifier->mag_data->factor_y = 2;
490 magnifier->mag_data->contrast = 0;
491 magnifier->mag_data->color_inverted = FALSE;
492 magnifier->mag_data->fast_rgb_convert = FALSE;
493 magnifier->mag_data->center.x = 0;
494 magnifier->mag_data->center.y = 0;
498 magnifier_get_type (void)
500 static GType type = 0;
503 static const GTypeInfo tinfo = {
504 sizeof (MagnifierClass),
505 (GBaseInitFunc) NULL,
506 (GBaseFinalizeFunc) NULL,
507 (GClassInitFunc) magnifier_class_init,
508 (GClassFinalizeFunc) NULL,
509 NULL, /* class data */
512 (GInstanceInitFunc) magnifier_init,
513 NULL /* value table */
516 * Here we use bonobo_type_unique instead of
517 * gtk_type_unique, this auto-generates a load of
518 * CORBA structures for us. All derived types must
519 * use bonobo_type_unique.
521 type = bonobo_type_unique (
523 POA_Accessibility_Magnifier__init,
525 G_STRUCT_OFFSET (MagnifierClass, epv),
534 magnifier_new (int argc, char **argv)
537 Magnifier *magnifier =
538 MAGNIFIER (g_object_new (magnifier_get_type(), NULL));
539 ctx = poptGetContext ("magnifier",
545 while (poptGetNextOpt (ctx) >= 0)