📄 magnifier.c
字号:
return CORBA_string_dup (magnifier->source_display_name ? magnifier->source_display_name : "");}static CORBA_stringimpl_magnifier_get_target_display (PortableServer_Servant servant, CORBA_Environment *ev){ Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant)); DBG (fprintf (stderr, "Get target display: \t%s\n", magnifier->target_display_name)); return CORBA_string_dup (magnifier->target_display_name ? magnifier->target_display_name : "");}static GNOME_Magnifier_ZoomRegionimpl_magnifier_create_zoom_region (PortableServer_Servant servant, const CORBA_float zx, const CORBA_float zy, const GNOME_Magnifier_RectBounds *roi, const GNOME_Magnifier_RectBounds *viewport, CORBA_Environment *ev){ Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant)); CORBA_any viewport_any; ZoomRegion *zoom_region = zoom_region_new (); Bonobo_PropertyBag properties; GNOME_Magnifier_ZoomRegion retval; DBG (fprintf (stderr, "Create zoom region: \tzoom %f,%f, viewport %d,%d to %d,%d\n", (float) zx, (float) zy, viewport->x1, viewport->y1, viewport->x2, viewport->y2)); /* FIXME: * shouldn't do this here, since it causes the region to get * mapped onto the parent, if if it's not explicitly added! */ DBG(g_message ("creating zoom region with parent %p", magnifier)); zoom_region->priv->parent = magnifier; retval = BONOBO_OBJREF (zoom_region); /* XXX: should check ev after each call, below */ CORBA_exception_init (ev); GNOME_Magnifier_ZoomRegion_setMagFactor (retval, zx, zy, ev); if (ev->_major != CORBA_NO_EXCEPTION) fprintf (stderr, "EXCEPTION setMagFactor\n"); CORBA_exception_init (ev); properties = GNOME_Magnifier_ZoomRegion_getProperties (retval, ev); if (ev->_major != CORBA_NO_EXCEPTION) fprintf (stderr, "EXCEPTION getProperties\n"); viewport_any._type = TC_GNOME_Magnifier_RectBounds; viewport_any._value = (gpointer) viewport; Bonobo_PropertyBag_setValue ( properties, "viewport", &viewport_any, ev); GNOME_Magnifier_ZoomRegion_setROI (retval, roi, ev); if (ev->_major != CORBA_NO_EXCEPTION) fprintf (stderr, "EXCEPTION setROI\n"); CORBA_exception_init (ev); gtk_widget_set_size_request (magnifier->priv->canvas, viewport->x2 - viewport->x1, viewport->y2 - viewport->y1); gtk_widget_show (magnifier->priv->canvas); gtk_widget_show (magnifier->priv->w); bonobo_object_release_unref (properties, ev); return CORBA_Object_duplicate (retval, ev);}staticCORBA_booleanimpl_magnifier_add_zoom_region (PortableServer_Servant servant, const GNOME_Magnifier_ZoomRegion region, CORBA_Environment * ev){ Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant)); if (!magnifier->source_initialized) { magnifier_set_extension_listeners (magnifier, magnifier_get_root (magnifier)); } /* FIXME: this needs proper lifecycle management */ magnifier->zoom_regions = g_list_append (magnifier->zoom_regions, region); magnifier_check_set_struts (magnifier); return CORBA_TRUE;}static Bonobo_PropertyBagimpl_magnifier_get_properties (PortableServer_Servant servant, CORBA_Environment *ev){ Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant)); return bonobo_object_dup_ref ( BONOBO_OBJREF (magnifier->property_bag), ev);}GNOME_Magnifier_ZoomRegionList *impl_magnifier_get_zoom_regions (PortableServer_Servant servant, CORBA_Environment * ev){ Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant)); GNOME_Magnifier_ZoomRegionList *list; CORBA_Object objref; int i, len; len = g_list_length (magnifier->zoom_regions); list = GNOME_Magnifier_ZoomRegionList__alloc (); list->_length = len; list->_buffer = GNOME_Magnifier_ZoomRegionList_allocbuf (list->_length); for (i = 0; i < len; ++i) { objref = g_list_nth_data (magnifier->zoom_regions, i); list->_buffer [i] = CORBA_Object_duplicate (objref, ev); } CORBA_sequence_set_release (list, CORBA_TRUE); DBG (fprintf (stderr, "Get zoom regions: \t%d\n", len)); return list; }static voidimpl_magnifier_clear_all_zoom_regions (PortableServer_Servant servant, CORBA_Environment * ev){ Magnifier *magnifier = MAGNIFIER (bonobo_object_from_servant (servant)); fprintf (stderr, "Clear all zoom regions.\n"); g_list_foreach (magnifier->zoom_regions, magnifier_unref_zoom_region, magnifier); g_list_free (magnifier->zoom_regions); magnifier->zoom_regions = NULL;}static voidimpl_magnifier_dispose (PortableServer_Servant servant, CORBA_Environment *ev){ magnifier_do_dispose ( MAGNIFIER (bonobo_object_from_servant (servant)));}static voidmagnifier_class_init (MagnifierClass *klass){ GObjectClass * object_class = (GObjectClass *) klass; POA_GNOME_Magnifier_Magnifier__epv *epv = &klass->epv; parent_class = g_type_class_peek (BONOBO_TYPE_OBJECT); /* needed by BONOBO_CALL_PARENT! */ object_class->dispose = magnifier_gobject_dispose; epv->_set_SourceDisplay = impl_magnifier_set_source_display; epv->_set_TargetDisplay = impl_magnifier_set_target_display; epv->_get_SourceDisplay = impl_magnifier_get_source_display; epv->_get_TargetDisplay = impl_magnifier_get_target_display; epv->getProperties = impl_magnifier_get_properties; epv->getZoomRegions = impl_magnifier_get_zoom_regions; epv->createZoomRegion = impl_magnifier_create_zoom_region; epv->addZoomRegion = impl_magnifier_add_zoom_region; epv->clearAllZoomRegions = impl_magnifier_clear_all_zoom_regions; epv->dispose = impl_magnifier_dispose;}static voidmagnifier_properties_init (Magnifier *magnifier){ BonoboArg *def; GNOME_Magnifier_RectBounds rect_bounds; gchar *display_env; magnifier->property_bag = bonobo_property_bag_new_closure ( g_cclosure_new_object ( G_CALLBACK (magnifier_get_property), G_OBJECT (magnifier)), g_cclosure_new_object ( G_CALLBACK (magnifier_set_property), G_OBJECT (magnifier))); /* Aggregate so magnifier implements Bonobo_PropertyBag */ bonobo_object_add_interface (BONOBO_OBJECT (magnifier), BONOBO_OBJECT (magnifier->property_bag)); def = bonobo_arg_new (BONOBO_ARG_STRING); display_env = getenv ("DISPLAY"); BONOBO_ARG_SET_STRING (def, display_env); bonobo_property_bag_add (magnifier->property_bag, "source-display-screen", MAGNIFIER_SOURCE_DISPLAY_PROP, BONOBO_ARG_STRING, def, "source display screen", Bonobo_PROPERTY_WRITEABLE); bonobo_property_bag_add (magnifier->property_bag, "target-display-screen", MAGNIFIER_TARGET_DISPLAY_PROP, BONOBO_ARG_STRING, def, "target display screen", Bonobo_PROPERTY_WRITEABLE); bonobo_arg_release (def); magnifier_init_display (magnifier, display_env, TRUE); magnifier_init_display (magnifier, display_env, FALSE); magnifier_get_display_rect_bounds (magnifier, &rect_bounds, FALSE); def = bonobo_arg_new_from (TC_GNOME_Magnifier_RectBounds, &rect_bounds); bonobo_property_bag_add (magnifier->property_bag, "source-display-bounds", MAGNIFIER_SOURCE_SIZE_PROP, TC_GNOME_Magnifier_RectBounds, def, "source display bounds/size", Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE); bonobo_arg_release (def); magnifier_get_display_rect_bounds (magnifier, &rect_bounds, TRUE); def = bonobo_arg_new_from (TC_GNOME_Magnifier_RectBounds, &rect_bounds); bonobo_property_bag_add (magnifier->property_bag, "target-display-bounds", MAGNIFIER_TARGET_SIZE_PROP, TC_GNOME_Magnifier_RectBounds, def, "target display bounds/size", Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE); bonobo_arg_release (def); bonobo_property_bag_add (magnifier->property_bag, "cursor-set", MAGNIFIER_CURSOR_SET_PROP, BONOBO_ARG_STRING, NULL, "name of cursor set", Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE); def = bonobo_arg_new (BONOBO_ARG_INT); BONOBO_ARG_SET_INT (def, 64); bonobo_property_bag_add (magnifier->property_bag, "cursor-size", MAGNIFIER_CURSOR_SIZE_PROP, BONOBO_ARG_INT, def, "cursor size, in pixels", Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE); bonobo_arg_release (def); bonobo_property_bag_add (magnifier->property_bag, "cursor-scale-factor", MAGNIFIER_CURSOR_ZOOM_PROP, BONOBO_ARG_FLOAT, NULL, "scale factor for cursors (overrides size)", Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE); bonobo_property_bag_add (magnifier->property_bag, "cursor-color", MAGNIFIER_CURSOR_COLOR_PROP, TC_CORBA_unsigned_long, NULL, "foreground color for 1-bit cursors, as ARGB", Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE); bonobo_property_bag_add (magnifier->property_bag, "cursor-hotspot", MAGNIFIER_CURSOR_HOTSPOT_PROP, TC_GNOME_Magnifier_Point, NULL, "hotspot relative to cursor's upper-left-corner, at default resolition", Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE); bonobo_property_bag_add (magnifier->property_bag, "cursor-default-size", MAGNIFIER_CURSOR_DEFAULT_SIZE_PROP, BONOBO_ARG_INT, NULL, "default size of current cursor set", Bonobo_PROPERTY_READABLE); bonobo_property_bag_add (magnifier->property_bag, "crosswire-size", MAGNIFIER_CROSSWIRE_SIZE_PROP, BONOBO_ARG_INT, NULL, "thickness of crosswire cursor, in target pixels", Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE); bonobo_property_bag_add (magnifier->property_bag, "crosswire-color", MAGNIFIER_CROSSWIRE_COLOR_PROP, BONOBO_ARG_LONG, NULL, "color of crosswire, as A-RGB; note that alpha is required. (use 0 for XOR wire)", Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE); bonobo_property_bag_add (magnifier->property_bag, "crosswire-clip", MAGNIFIER_CROSSWIRE_CLIP_PROP, BONOBO_ARG_BOOLEAN, NULL, "whether to inset the cursor over the crosswire or not", Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE);}static voidmagnifier_init_window (Magnifier *magnifier, GdkScreen *screen){ GtkWindowType mag_win_type = GTK_WINDOW_TOPLEVEL; if (_is_override_redirect) mag_win_type = GTK_WINDOW_POPUP; magnifier->priv->w = g_object_connect (gtk_widget_new (gtk_window_get_type (), "user_data", NULL, "can_focus", FALSE, "type", mag_win_type, "title", "magnifier", "allow_grow", TRUE, "allow_shrink", TRUE, "border_width", 0, NULL), "signal::realize", magnifier_realize, NULL, "signal::size_allocate", magnifier_size_allocate, NULL, "signal::destroy", magnifier_exit, NULL, NULL); gtk_window_set_screen (GTK_WINDOW (magnifier->priv->w), screen); magnifier->priv->canvas = gtk_fixed_new (); gtk_container_add (GTK_CONTAINER (magnifier->priv->w), magnifier->priv->canvas); magnifier->priv->root = NULL;}static voidmagnifier_init (Magnifier *magnifier){ magnifier->priv = g_new0 (MagnifierPrivate, 1); magnifier_properties_init (magnifier); magnifier->zoom_regions = NULL; magnifier->source_screen_num = 0; magnifier->target_screen_num = 0; magnifier->source_display_name = g_strdup (":0.0"); magnifier->target_display_name = g_strdup (":0.0"); magnifier->cursor_size_x = 0; magnifier->cursor_size_y = 0; magnifier->cursor_scale_factor = 1.0F; magnifier->cursor_color = 0xFF000000; magnifier->crosswire_size = 1; magnifier->crosswire_color = 0; magnifier->crosswire_clip = FALSE; magnifier->cursor_hotspot.x = 0; magnifier->cursor_hotspot.y = 0; magnifier->priv->cursor = NULL; magnifier->priv->w = NULL; magnifier->priv->use_source_cursor = TRUE; magnifier->priv->cursorlist = NULL; magnifier->priv->source_drawable = NULL; magnifier->priv->overlay = NULL; magnifier_init_window (magnifier, gdk_display_get_screen (magnifier->target_display, magnifier->target_screen_num)); magnifier_init_cursor_set (magnifier, "default"); mag_timing.process = g_timer_new (); mag_timing.frame = g_timer_new (); mag_timing.scale = g_timer_new (); mag_timing.idle = g_timer_new ();#ifdef DEBUG_CLIENT_CALLS client_debug = (g_getenv ("MAG_CLIENT_DEBUG") != NULL);#endif}GdkDrawable *magnifier_get_cursor (Magnifier *magnifier){ if (magnifier->priv->cursor == NULL) { if ((fixes_event_base == 0) && strcmp (magnifier->cursor_set, "none")) { GdkPixbuf *pixbuf; gchar *default_cursor_filename = g_strconcat (CURSORSDIR, "/", "default-cursor.xpm", NULL); pixbuf = gdk_pixbuf_new_from_file (default_cursor_filename, NULL); if (pixbuf) { magnifier_set_cursor_from_pixbuf (magnifier, pixbuf); g_object_unref (pixbuf); magnifier_transform_cursor (magnifier); } g_free (default_cursor_filename); }#ifdef HAVE_XFIXES else { GdkPixbuf *cursor_pixbuf = gmag_events_get_source_pixbuf ( magnifier); magnifier_set_cursor_from_pixbuf (magnifier, cursor_pixbuf); if (cursor_pixbuf) g_object_unref (cursor_pixbuf); magnifier_transform_cursor (magnifier); }#endif } return magnifier->priv->cursor;}Magnifier *magnifier_new (gboolean override_redirect){ Magnifier *mag; MagLoginHelper *helper; int ret; _is_override_redirect = override_redirect; mag = g_object_new (magnifier_get_type(), NULL); _this_magnifier = mag; /* FIXME what about multiple instances? */ helper = g_object_new (mag_login_helper_get_type (), NULL); mag_login_helper_set_magnifier (helper, mag); bonobo_object_add_interface (bonobo_object (mag), BONOBO_OBJECT (helper)); ret = bonobo_activation_active_server_register ( MAGNIFIER_OAFIID, BONOBO_OBJREF (mag)); if (ret != Bonobo_ACTIVATION_REG_SUCCESS) if ( ret == Bonobo_ACTIVATION_REG_ALREADY_ACTIVE) { printf("An instance of magnifier is already active. Exiting Program.\n"); exit(0); } else g_error ("Error registering magnifier server.\n"); g_idle_add (magnifier_reset_struts_at_idle, mag); g_idle_add (magnifier_reset_overlay_at_idle, mag); return mag;}BONOBO_TYPE_FUNC_FULL (Magnifier, GNOME_Magnifier_Magnifier, BONOBO_TYPE_OBJECT, magnifier)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -