static void xfce_keyboard_layout_helper_init (XfceKeyboardLayoutHelper *helper) { /* init */ helper->channel = NULL; /* open the channel */ helper->channel = xfconf_channel_get ("keyboard-layout"); helper->xkb_disable_settings = xfconf_channel_get_bool (helper->channel, "/Default/XkbDisable", TRUE); #ifdef HAVE_LIBXKLAVIER /* monitor channel changes */ g_signal_connect (G_OBJECT (helper->channel), "property-changed", G_CALLBACK (xfce_keyboard_layout_helper_channel_property_changed), helper); helper->engine = xkl_engine_get_instance (GDK_DISPLAY ()); helper->config = xkl_config_rec_new (); xkl_config_rec_get_from_server (helper->config, helper->engine); helper->system_keyboard_model = g_strdup (helper->config->model); gdk_window_add_filter (NULL, (GdkFilterFunc) handle_xevent, helper); g_signal_connect (helper->engine, "X-new-device", G_CALLBACK (xfce_keyboard_layout_reset_xkl_config), helper); xkl_engine_start_listen (helper->engine, XKLL_TRACK_KEYBOARD_STATE); /* load settings */ xfce_keyboard_layout_helper_set_model (helper); xfce_keyboard_layout_helper_set_layout (helper); xfce_keyboard_layout_helper_set_variant (helper); xfce_keyboard_layout_helper_set_grpkey (helper); xfce_keyboard_layout_helper_set_composekey (helper); #endif /* HAVE_LIBXKLAVIER */ xfce_keyboard_layout_helper_process_xmodmap (); }
static gboolean tvm_block_device_autophoto (TvmContext *context, GMount *mount, GError **error) { gboolean autophoto; gboolean result = FALSE; gchar *autophoto_command; gint response; g_return_val_if_fail (context != NULL, FALSE); g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); /* check if autophoto support is enabled */ autophoto = xfconf_channel_get_bool (context->channel, "/autophoto/enabled", FALSE); if (autophoto) { autophoto_command = xfconf_channel_get_string (context->channel, "/autophoto/command", NULL); if (autophoto_command != NULL && *autophoto_command != '\0') { /* check if we have any photos on the volume */ if (tvm_file_test (mount, "dcim", G_FILE_TEST_IS_DIR)) { /* ask the user to import photos */ response = tvm_prompt (context, "camera-photo", _("Photo Import"), _("A photo card has been detected"), _("There are photos on the card. Would you like to " "add these photos to your album?"), _("Ig_nore"), GTK_RESPONSE_CANCEL, _("Import _Photos"), TVM_RESPONSE_PHOTOS, NULL); if (response == TVM_RESPONSE_PHOTOS) { /* run the preferred photo application */ result = tvm_run_command (context, mount, autophoto_command, error); } else { /* pretend that we handled the device */ result = TRUE; } } } g_free (autophoto_command); } return result; }
void sm_init (XfconfChannel *channel, gboolean disable_tcp, XfsmManager *manager) { char *network_idlist; char error[2048]; if (disable_tcp || !xfconf_channel_get_bool (channel, "/security/EnableTcp", FALSE)) { #ifdef HAVE__ICETRANSNOLISTEN _IceTransNoListen ("tcp"); #else fprintf (stderr, "xfce4-session: Requested to disable tcp connections, but " "_IceTransNoListen is not available on this plattform. " "Request will be ignored.\n"); xfsm_verbose ("_IceTransNoListen unavailable on this platform"); #endif } if (!SmsInitialize (PACKAGE, VERSION, sm_new_client, manager, ice_auth_proc, 2048, error)) { fprintf (stderr, "xfce4-session: Unable to register XSM protocol: %s\n", error); /* log to verbose so we don't have to look at both files */ xfsm_verbose ("xfce4-session: Unable to register XSM protocol: %s\n", error); exit (EXIT_FAILURE); } if (!IceListenForConnections (&num_listeners, &listen_objs, 2048, error)) { fprintf (stderr, "xfce4-session: Unable to establish ICE listeners: %s\n", error); /* log to verbose so we don't have to look at both files */ xfsm_verbose ("xfce4-session: Unable to establish ICE listeners: %s\n", error); exit (EXIT_FAILURE); } ice_setup_listeners (num_listeners, listen_objs, manager); network_idlist = IceComposeNetworkIdList (num_listeners, listen_objs); g_setenv ("SESSION_MANAGER", network_idlist, TRUE); free (network_idlist); }
static void xfce_accessibility_helper_set_xkb (XfceAccessibilityHelper *helper, gulong mask) { XkbDescPtr xkb; gint delay, interval, time_to_max; gint max_speed, curve; gdk_error_trap_push (); /* allocate */ xkb = XkbAllocKeyboard (); if (G_LIKELY (xkb)) { /* we always change this, so add it to the mask */ SET_FLAG (mask, XkbControlsEnabledMask); /* if setting sticky keys, we set expiration too */ if (HAS_FLAG (mask, XkbStickyKeysMask) || HAS_FLAG (mask, XkbSlowKeysMask) || HAS_FLAG (mask, XkbBounceKeysMask) || HAS_FLAG (mask, XkbMouseKeysMask) || HAS_FLAG (mask, XkbAccessXKeysMask)) SET_FLAG (mask, XkbAccessXTimeoutMask); /* add the mouse keys values mask if needed */ if (HAS_FLAG (mask, XkbMouseKeysMask)) SET_FLAG (mask, XkbMouseKeysAccelMask); /* load the xkb controls into the structure */ XkbGetControls (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), mask, xkb); /* AccessXKeys */ if (HAS_FLAG (mask, XkbAccessXKeysMask)) { if (xfconf_channel_get_bool (helper->channel, "/AccessXKeys", FALSE)) { SET_FLAG (xkb->ctrls->enabled_ctrls, XkbAccessXKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbAccessXKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbAccessXKeysMask); xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "AccessXKeys enabled"); } else { UNSET_FLAG (xkb->ctrls->enabled_ctrls, XkbAccessXKeysMask); SET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbAccessXKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbAccessXKeysMask); xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "AccessXKeys disabled"); } } /* Sticky keys */ if (HAS_FLAG (mask, XkbStickyKeysMask)) { if (xfconf_channel_get_bool (helper->channel, "/StickyKeys", FALSE)) { SET_FLAG (xkb->ctrls->enabled_ctrls, XkbStickyKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbStickyKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbStickyKeysMask); if (xfconf_channel_get_bool (helper->channel, "/StickyKeys/LatchToLock", FALSE)) SET_FLAG (xkb->ctrls->ax_options, XkbAX_LatchToLockMask); else UNSET_FLAG (xkb->ctrls->ax_options, XkbAX_LatchToLockMask); if (xfconf_channel_get_bool (helper->channel, "/StickyKeys/TwoKeysDisable", FALSE)) SET_FLAG (xkb->ctrls->ax_options, XkbAX_TwoKeysMask); else UNSET_FLAG (xkb->ctrls->ax_options, XkbAX_TwoKeysMask); xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "stickykeys enabled (ax_options=%d)", xkb->ctrls->ax_options); } else { UNSET_FLAG (xkb->ctrls->enabled_ctrls, XkbStickyKeysMask); SET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbStickyKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbStickyKeysMask); xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "stickykeys disabled"); } } /* Slow keys */ if (HAS_FLAG (mask, XkbSlowKeysMask)) { if (xfconf_channel_get_bool (helper->channel, "/SlowKeys", FALSE)) { SET_FLAG (xkb->ctrls->enabled_ctrls, XkbSlowKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbSlowKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbSlowKeysMask); delay = xfconf_channel_get_int (helper->channel, "/SlowKeys/Delay", 100); xkb->ctrls->slow_keys_delay = CLAMP (delay, 1, G_MAXUSHORT); xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "slowkeys enabled (delay=%d)", xkb->ctrls->slow_keys_delay); } else { UNSET_FLAG (xkb->ctrls->enabled_ctrls, XkbSlowKeysMask); SET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbSlowKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbSlowKeysMask); xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "slowkeys disabled"); } } /* Bounce keys */ if (HAS_FLAG (mask, XkbBounceKeysMask)) { if (xfconf_channel_get_bool (helper->channel, "/BounceKeys", FALSE)) { SET_FLAG (xkb->ctrls->enabled_ctrls, XkbBounceKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbBounceKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbBounceKeysMask); delay = xfconf_channel_get_int (helper->channel, "/BounceKeys/Delay", 100); xkb->ctrls->debounce_delay = CLAMP (delay, 1, G_MAXUSHORT); xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "bouncekeys enabled (delay=%d)", xkb->ctrls->debounce_delay); } else { UNSET_FLAG (xkb->ctrls->enabled_ctrls, XkbBounceKeysMask); SET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbBounceKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbBounceKeysMask); xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "bouncekeys disabled"); } } /* Mouse keys */ if (HAS_FLAG (mask, XkbMouseKeysMask)) { if (xfconf_channel_get_bool (helper->channel, "/MouseKeys", FALSE)) { SET_FLAG (xkb->ctrls->enabled_ctrls, XkbMouseKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbMouseKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbMouseKeysMask); /* get values */ delay = xfconf_channel_get_int (helper->channel, "/MouseKeys/Delay", 160); interval = xfconf_channel_get_int (helper->channel, "/MouseKeys/Interval", 20); time_to_max = xfconf_channel_get_int (helper->channel, "/MouseKeys/TimeToMax", 3000); max_speed = xfconf_channel_get_int (helper->channel, "/MouseKeys/MaxSpeed", 1000); curve = xfconf_channel_get_int (helper->channel, "/MouseKeys/Curve", 0); /* calculate maximum speed and to to reach it */ interval = CLAMP (interval, 1, G_MAXUSHORT); max_speed = (max_speed * interval) / 1000; time_to_max = (time_to_max + interval / 2) / interval; /* set new values, clamp to limits */ xkb->ctrls->mk_delay = CLAMP (delay, 1, G_MAXUSHORT); xkb->ctrls->mk_interval = interval; xkb->ctrls->mk_time_to_max = CLAMP (time_to_max, 1, G_MAXUSHORT); xkb->ctrls->mk_max_speed = CLAMP (max_speed, 1, G_MAXUSHORT); xkb->ctrls->mk_curve = CLAMP (curve, -1000, 1000); xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "mousekeys enabled (delay=%d, interval=%d, " "time_to_max=%d, max_speed=%d, curve=%d)", xkb->ctrls->mk_delay, xkb->ctrls->mk_interval, xkb->ctrls->mk_time_to_max, xkb->ctrls->mk_max_speed, xkb->ctrls->mk_curve); } else { UNSET_FLAG (xkb->ctrls->enabled_ctrls, XkbMouseKeysMask); SET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbMouseKeysMask); UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbMouseKeysMask); UNSET_FLAG (mask, XkbMouseKeysAccelMask); xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "mousekeys disabled"); } } /* set the modified controls */ if (!XkbSetControls (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), mask, xkb)) g_message ("Setting the xkb controls failed"); /* free the structure */ XkbFreeControls (xkb, mask, True); XFree (xkb); } else { /* warning */ g_critical ("XkbAllocKeyboard() returned a null pointer"); } if (gdk_error_trap_pop () != 0) g_critical ("Failed to set keyboard controls"); }
static gboolean tvm_block_device_autorun (TvmContext *context, GMount *mount, GError **error) { struct stat statb_mount_point; struct stat statb_autoopen; gboolean autoopen; gboolean autoplay; gboolean autorun; gboolean result = FALSE; GError *err = NULL; GFile *mount_point; gchar **argv; gchar *autoplay_command; gchar *message; gchar *mount_path; gchar *path_autoopen; gchar *wine; gchar line[1024]; guint n; FILE *fp; gint response; g_return_val_if_fail (context != NULL, FALSE); g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); /* check if autoplaying video CDs and DVDs is enabled */ autoplay = xfconf_channel_get_bool (context->channel, "/autoplay-video-cds/enabled", FALSE); if (autoplay) { /* check if we have a video CD or video DVD here */ if (tvm_file_test (mount, "vcd", G_FILE_TEST_IS_DIR) || tvm_file_test (mount, "video_ts", G_FILE_TEST_IS_DIR)) { /* determine the autoplay command for video CDs/DVDs */ autoplay_command = xfconf_channel_get_string (context->channel, "/autoplay-video-cds/command", "parole"); /* try to spawn the preferred video CD/DVD player */ result = tvm_run_command (context, mount, autoplay_command, &err); /* free the command string */ g_free (autoplay_command); /* forward errors to the caller */ if (err != NULL) g_propagate_error (error, err); /* return success/failure to the caller */ return result; } } /* check if autorun is enabled */ autorun = xfconf_channel_get_bool (context->channel, "/autorun/enabled", FALSE); if (autorun) { /* Autostart files according to the Desktop Application Autostart * Specification */ static const gchar *autorun_files[] = { ".autorun", "autorun", "autorun.sh" }; for (n = 0; n < G_N_ELEMENTS (autorun_files); ++n) { /* check if one of the autorun files is present and executable */ if (tvm_file_test (mount, autorun_files[n], G_FILE_TEST_IS_EXECUTABLE) && tvm_file_test (mount, autorun_files[n], G_FILE_TEST_IS_REGULAR)) { /* prompt the user to execute the file */ message = g_strdup_printf (_("Would you like to allow \"%s\" to run?"), autorun_files[n]); response = tvm_prompt (context, "gnome-fs-executable", _("Auto-Run Confirmation"), _("Auto-Run capability detected"), message, _("Ig_nore"), GTK_RESPONSE_CANCEL, _("_Allow Auto-Run"), TVM_RESPONSE_AUTORUN, NULL); g_free (message); /* check if we should autorun */ if (response == TVM_RESPONSE_AUTORUN) { /* determine the mount point as a string */ mount_point = g_mount_get_root (mount); mount_path = g_file_get_path (mount_point); g_object_unref (mount_point); /* prepare argv to launch the autorun file */ argv = g_new0 (gchar *, 2); argv[0] = g_build_filename (mount_path, autorun_files[n], NULL); argv[1] = NULL; /* try to launch the autorun file */ result = g_spawn_async (mount_path, argv, NULL, 0, NULL, NULL, NULL, &err); /* free strings */ g_strfreev (argv); g_free (mount_path); if (err != NULL) g_propagate_error (error, err); return result; } } }
static gboolean tvm_block_device_autoipod (TvmContext *context, GMount *mount, GError **error) { gboolean autoipod; gboolean is_audio_player = FALSE; gboolean is_ipod = FALSE; gboolean result = FALSE; GFile *mount_point; gchar *autoipod_command; gchar *autophoto_command; gchar *mount_path; gchar *path_dcim = NULL; gint response = TVM_RESPONSE_NONE; g_return_val_if_fail (context != NULL, FALSE); g_return_val_if_fail (G_IS_MOUNT (mount), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); autoipod = xfconf_channel_get_bool (context->channel, "/autoipod/enabled", FALSE); if (autoipod) { /* check if we have a portable audio player here */ is_audio_player = g_udev_device_has_property (context->device, "ID_MEDIA_PLAYER"); /* check if we have an iPod */ is_ipod = g_str_has_prefix (g_udev_device_get_property (context->device, "ID_MODEL"), "iPod"); if (is_ipod) { /* determine the mount point path */ mount_point = g_mount_get_root (mount); mount_path = g_file_get_path (mount_point); g_object_unref (mount_point); /* build dcim path */ path_dcim = g_build_filename (mount_path, "dcim", NULL); g_free (mount_path); /* check if the iPod has photos */ if (!g_file_test (path_dcim, G_FILE_TEST_IS_DIR)) { /* no photos */ g_free (path_dcim); path_dcim = NULL; } } autoipod_command = xfconf_channel_get_string (context->channel, "/autoipod/command", NULL); autophoto_command = xfconf_channel_get_string (context->channel, "/autophoto/command", NULL); /* check if autophoto command is specified, otherwise we cannot handle the photos * on the iPod anyway */ if (autophoto_command == NULL || *autophoto_command == '\0') { g_free (path_dcim); path_dcim = NULL; } /* iPods can carry music and photos... */ if (path_dcim != NULL) { /* ...so we need to prompt what to do */ response = tvm_prompt (context, "multimedia-player", _("Photos and Music"), _("Photos were found on your portable music player"), _("Would you like to import the photos or manage the " "music?"), _("Ig_nore"), GTK_RESPONSE_CANCEL, _("Import _Photos"), TVM_RESPONSE_PHOTOS, _("Manage _Music"), TVM_RESPONSE_MUSIC, NULL); } else if (is_audio_player || is_ipod) { response = TVM_RESPONSE_MUSIC; } /* check what to do */ if (response == TVM_RESPONSE_MUSIC) { /* run the preferred application to manage music players */ result = tvm_run_command (context, mount, autoipod_command, error); } else if (response == TVM_RESPONSE_PHOTOS) { /* run the preferred application to manage photos */ result = tvm_run_command (context, mount, autophoto_command, error); } else if (path_dcim != NULL) { /* when the user has decided to ignore photos/music, we don't want * to ask him again in autophoto and we don't want to mount the * device either... I guess? */ result = TRUE; } g_free (autophoto_command); g_free (autoipod_command); g_free (path_dcim); } return result; }
void tvm_usb_device_added (TvmContext *context) { const gchar *icon; const gchar *summary; const gchar *message; const gchar *driver; const gchar *enabled_property = NULL; const gchar *command_property = NULL; gboolean enabled; gboolean is_camera; gchar *command; g_return_if_fail (context != NULL); /* collect device information */ driver = g_udev_device_get_property (context->device, "DRIVER"); is_camera = g_udev_device_get_property_as_boolean (context->device, "ID_GPHOTO2"); if (is_camera) { enabled_property = "/autophoto/enabled"; command_property = "/autophoto/command"; icon = "camera-photo"; summary = _("Camera detected"); message = _("A photo camera was detected"); } else if (g_strcmp0 (driver, "usblp") == 0) { enabled_property = "/autoprinter/enabled"; command_property = "/autoprinter/command"; icon = "printer"; summary = _("Printer detected"); message = _("A USB printer was detected"); } /* check if we have a device that we support */ if (enabled_property != NULL && command_property != NULL) { /* check whether handling the printer or whatever is enabled */ enabled = xfconf_channel_get_bool (context->channel, enabled_property, FALSE); if (enabled) { #ifdef HAVE_LIBNOTIFY /* display a detection notification */ tvm_notify (icon, summary, message); #endif /* fetch the command for the input device type and try to run it */ command = xfconf_channel_get_string (context->channel, command_property, NULL); if (command != NULL && *command != '\0') { tvm_run_command (context, NULL, command, context->error); } g_free (command); } } else { /* return an error because we cannot handle the usb device */ g_set_error (context->error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Unsupported USB device type \"%s\""), driver); } /* finish processing the device */ tvm_device_handler_finished (context); }