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 gdk_window_resize (window->window, magnifier->mag_data->mag_width, magnifier->mag_data->mag_height);
249 magnifier->mag_data->output_window = window;
250 if (global_options.fullscreen) gdk_window_stick (window->window);
251 gdk_window_set_functions(window->window, 0);
252 gdk_window_raise(window->window);
254 gtk_timeout_add(global_options.min_refresh_time, display_image, magnifier->mag_data);
256 obj_id = "OAFIID:Accessibility_Util_Magnifier:proto0.1";
258 if (! global_options.no_bonobo)
260 bonobo_activation_active_server_register (
262 bonobo_object_corba_objref (bonobo_object (magnifier)));
271 unlink("magnifier_socket");
276 impl_magnifier_fullscreen (PortableServer_Servant servant,
277 CORBA_Environment *ev)
279 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
280 magnifier->mag_data->mag_width = DisplayWidth (magnifier->mag_data->target_display, screen_num);
281 magnifier->mag_data->mag_height = DisplayHeight (magnifier->mag_data->target_display, screen_num);
285 impl_magnifier_set_extents (PortableServer_Servant servant,
290 CORBA_Environment *ev)
292 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
293 magnifier->mag_data->mag_width = x2 - x1;
294 magnifier->mag_data->mag_height = y2 - y1;
295 gdk_window_move(window->window, x1, y1);
299 impl_magnifier_set_follow_mouse (PortableServer_Servant servant,
300 const CORBA_boolean follow_mouse,
301 CORBA_Environment *ev)
303 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
304 magnifier->mag_data->follow_mouse = (int) follow_mouse;
308 impl_magnifier_set_contrast (PortableServer_Servant servant,
309 const CORBA_short contrast,
310 CORBA_Environment *ev)
312 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
313 magnifier->mag_data->contrast = (int) contrast;
317 impl_magnifier_set_source_display (PortableServer_Servant servant,
318 const CORBA_char *display,
319 CORBA_Environment *ev)
321 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
322 magnifier->mag_data->source_display =
323 XOpenDisplay (global_options.source_display);
327 impl_magnifier_set_target_display (PortableServer_Servant servant,
328 const CORBA_char *display,
329 CORBA_Environment *ev)
331 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
332 magnifier->mag_data->target_display = GDK_DISPLAY();
336 impl_magnifier_goto (PortableServer_Servant servant,
339 CORBA_Environment *ev)
341 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
342 magnifier->mag_data->center.x = (int) x;
343 magnifier->mag_data->center.y = (int) y;
347 impl_magnifier_set_roi (PortableServer_Servant servant,
348 const CORBA_short zoom_region,
353 CORBA_Environment *ev)
355 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
356 magnifier->mag_data->center.x = (int) ((x1 + x2)/2);
357 magnifier->mag_data->center.y = (int) ((y1 + y2)/2);
361 impl_magnifier_set_mag_factor (PortableServer_Servant servant,
362 const CORBA_short zoom_region,
363 const CORBA_float mag_factor_x,
364 const CORBA_float mag_factor_y,
365 CORBA_Environment *ev)
367 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
368 if (zoom_region == (CORBA_short) 0) /* TODO: fix for multi-zoom-regions */
370 magnifier->mag_data->factor_x = (float) mag_factor_x;
371 magnifier->mag_data->factor_y = (float) mag_factor_y;
376 impl_magnifier_mark_dirty (PortableServer_Servant servant,
377 const CORBA_short zoom_region,
378 CORBA_Environment *ev)
380 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
381 /* TODO: implement */
385 impl_magnifier_mark_unmanaged (PortableServer_Servant servant,
386 const CORBA_short zoom_region,
387 CORBA_Environment *ev)
389 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
390 /* TODO: implement */
394 impl_magnifier_create_zoom_region (PortableServer_Servant servant,
395 const CORBA_float zx,
396 const CORBA_float zy,
401 CORBA_Environment *ev)
403 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
408 impl_magnifier_get_zoom_region_params (PortableServer_Servant servant,
409 const CORBA_short zoom_region,
411 CORBA_float * zy, CORBA_long * x1,
412 CORBA_long * y1, CORBA_long * x2,
414 CORBA_Environment * ev)
416 Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant));
417 if (zoom_region == (CORBA_short) 0)
419 *zx = magnifier->mag_data->factor_x;
420 *zy = magnifier->mag_data->factor_y;
423 *x2 = *x1 + magnifier->mag_data->mag_width;
424 *y2 = *y1 + magnifier->mag_data->mag_height;
427 else return CORBA_FALSE;
431 impl_magnifier_resize_zoom_region (PortableServer_Servant _servant,
432 const CORBA_short zoom_region,
433 const CORBA_long x1, const CORBA_long y1,
434 const CORBA_long x2, const CORBA_long y2,
435 CORBA_Environment * ev)
440 impl_magnifier_destroy_zoom_region (PortableServer_Servant _servant,
441 const CORBA_short zoom_region,
442 CORBA_Environment * ev)
447 impl_magnifier_clear_all_zoom_regions (PortableServer_Servant _servant,
448 CORBA_Environment * ev)
453 impl_magnifier_exit (PortableServer_Servant servant, CORBA_Environment *ev)
459 magnifier_class_init (MagnifierClass *klass)
461 GObjectClass * object_class = (GObjectClass *) klass;
462 POA_Accessibility_Magnifier__epv *epv = &klass->epv;
464 object_class->finalize = magnifier_finalize;
466 epv->_set_SourceDisplay = impl_magnifier_set_source_display;
467 epv->_set_TargetDisplay = impl_magnifier_set_target_display;
468 epv->setROI = impl_magnifier_set_roi;
469 epv->setMagFactor = impl_magnifier_set_mag_factor;
470 epv->markDirty = impl_magnifier_mark_dirty;
471 epv->markUnmanaged = impl_magnifier_mark_unmanaged;
472 epv->createZoomRegion = impl_magnifier_create_zoom_region;
473 epv->getZoomRegionParams = impl_magnifier_get_zoom_region_params;
474 epv->resizeZoomRegion = impl_magnifier_resize_zoom_region;
475 epv->destroyZoomRegion = impl_magnifier_destroy_zoom_region;
476 epv->clearAllZoomRegions = impl_magnifier_clear_all_zoom_regions;
477 epv->exit = impl_magnifier_exit;
481 magnifier_init (Magnifier *magnifier)
483 magnifier->mag_data = (MagnifierData *) g_new0 (MagnifierData, 1);
484 magnifier->mag_data->factor_x = 2;
485 magnifier->mag_data->factor_y = 2;
486 magnifier->mag_data->contrast = 0;
487 magnifier->mag_data->color_inverted = FALSE;
488 magnifier->mag_data->fast_rgb_convert = FALSE;
489 magnifier->mag_data->center.x = 0;
490 magnifier->mag_data->center.y = 0;
494 magnifier_get_type (void)
496 static GType type = 0;
499 static const GTypeInfo tinfo = {
500 sizeof (MagnifierClass),
501 (GBaseInitFunc) NULL,
502 (GBaseFinalizeFunc) NULL,
503 (GClassInitFunc) magnifier_class_init,
504 (GClassFinalizeFunc) NULL,
505 NULL, /* class data */
508 (GInstanceInitFunc) magnifier_init,
509 NULL /* value table */
512 * Here we use bonobo_type_unique instead of
513 * gtk_type_unique, this auto-generates a load of
514 * CORBA structures for us. All derived types must
515 * use bonobo_type_unique.
517 type = bonobo_type_unique (
519 POA_Accessibility_Magnifier__init,
521 G_STRUCT_OFFSET (MagnifierClass, epv),
530 magnifier_new(int argc, char **argv)
533 Magnifier *magnifier =
534 MAGNIFIER (g_object_new (magnifier_get_type(), NULL));
535 ctx = poptGetContext ("magnifier",
541 while (poptGetNextOpt (ctx) >= 0)