Ticket #4133: 0001-Allow-running-clipboard-commands-if-DISPLAY-is-not-s.patch

File 0001-Allow-running-clipboard-commands-if-DISPLAY-is-not-s.patch, 5.7 KB (added by devzero, 4 years ago)
  • doc/man/mc.1.in

    From 6b02ee48c72841221c88dbdb74dc5b52808c43aa Mon Sep 17 00:00:00 2001
    From: Vadim Ushakov <igeekless@gmail.com>
    Date: Fri, 16 Oct 2020 00:01:30 +0700
    Subject: [PATCH] Allow running clipboard commands if DISPLAY is not set
    
    Implement a new configuration variable clipboard_force_no_display that
    allows running commands specified in clipboard_store clipboard_paste even
    if the DISPLAY environment variable is not set.
    
    This can be used for running a clipboard script (from a virtual terminal)
    that autodetects (or requests from sytemctl) the proper values of DISPLAY
    and XAUTHORITY without the need of exporting these variables to the whole
    virtual terminal session.
    ---
     doc/man/mc.1.in    | 11 +++++++++++
     doc/man/ru/mc.1.in | 14 +++++++++++++-
     src/clipboard.c    | 11 +++++++----
     src/clipboard.h    |  1 +
     src/setup.c        |  4 ++++
     5 files changed, 36 insertions(+), 5 deletions(-)
    
    diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in
    index cdd1f687b..fb2fdef4e 100644
    a b For example: 
    41924192clipboard_paste=xclip \-o 
    41934193.fi 
    41944194.TP 
     4195.I clipboard_force_no_display 
     4196Normally, Midnight Commander doesn't run commands specified in 
     4197.I clipboard_store 
     4198and 
     4199.I clipboard_paste 
     4200if the 
     4201.B DISPLAY 
     4202environment variable is not set. Setting this variable to true forces 
     4203Midnight Commander to run the commands unconditionally. 
     4204.fi 
     4205.TP 
    41954206.I autodetect_codeset 
    41964207This option allows use the `enca' command to autodetect codeset of text files 
    41974208in internal viewer and editor. List of valid values can be obtain by the 
  • doc/man/ru/mc.1.in

    diff --git a/doc/man/ru/mc.1.in b/doc/man/ru/mc.1.in
    index f029b5f3e..6e2f1497b 100644
    a b clipboard_store=xclip \-i 
    47624762.nf 
    47634763clipboard_paste=xclip \-o 
    47644764.fi 
    4765 .PP 
     4765.TP 
     4766.I clipboard_force_no_display 
     4767По умолчанию Midnight Commander не запускает команды, указанные в  
     4768.I clipboard_store 
     4769и 
     4770.I clipboard_paste\fR, 
     4771если переменная окружения 
     4772.B DISPLAY 
     4773не установлена. Установка этой переменной в значение true обеспечивает 
     4774принудительное исполнение команд без проверки переменной 
     4775.B DISPLAY\fR. 
     4776.fi 
     4777.TP 
    47664778.I autodetect_codeset 
    47674779.IP 
    47684780Эта опция позволяет использовать команду enca для автоматического 
  • src/clipboard.c

    diff --git a/src/clipboard.c b/src/clipboard.c
    index 4e0b60c0b..5cceb6047 100644
    a b  
    4848char *clipboard_store_path = NULL; 
    4949char *clipboard_paste_path = NULL; 
    5050 
     51/* whether to run commands when DISPLAY is not set */ 
     52gboolean clipboard_force_no_display = 0; 
     53 
    5154/*** file scope macro definitions ****************************************************************/ 
    5255 
    5356/*** file scope type declarations ****************************************************************/ 
    clipboard_file_to_ext_clip (const gchar * event_group_name, const gchar * event_ 
    7174                            gpointer init_data, gpointer data) 
    7275{ 
    7376    char *tmp, *cmd; 
    74     const char *d = getenv ("DISPLAY"); 
     77    gboolean allowed = (clipboard_force_no_display) || (getenv ("DISPLAY") != NULL); 
    7578 
    7679    (void) event_group_name; 
    7780    (void) event_name; 
    7881    (void) init_data; 
    7982    (void) data; 
    8083 
    81     if (d == NULL || clipboard_store_path == NULL || clipboard_store_path[0] == '\0') 
     84    if (!allowed || clipboard_store_path == NULL || clipboard_store_path[0] == '\0') 
    8285        return TRUE; 
    8386 
    8487    tmp = mc_config_get_full_path (EDIT_HOME_CLIP_FILE); 
    clipboard_file_from_ext_clip (const gchar * event_group_name, const gchar * even 
    101104{ 
    102105    mc_pipe_t *p; 
    103106    int file = -1; 
    104     const char *d = getenv ("DISPLAY"); 
     107    gboolean allowed = (clipboard_force_no_display) || (getenv ("DISPLAY") != NULL); 
    105108 
    106109    (void) event_group_name; 
    107110    (void) event_name; 
    108111    (void) init_data; 
    109112    (void) data; 
    110113 
    111     if (d == NULL || clipboard_paste_path == NULL || clipboard_paste_path[0] == '\0') 
     114    if (!allowed || clipboard_paste_path == NULL || clipboard_paste_path[0] == '\0') 
    112115        return TRUE; 
    113116 
    114117    p = mc_popen (clipboard_paste_path, NULL); 
  • src/clipboard.h

    diff --git a/src/clipboard.h b/src/clipboard.h
    index 9b2fc2216..a701e3655 100644
    a b  
    1515 
    1616extern char *clipboard_store_path; 
    1717extern char *clipboard_paste_path; 
     18extern gboolean clipboard_force_no_display; 
    1819 
    1920/*** declarations of public functions ************************************************************/ 
    2021 
  • src/setup.c

    diff --git a/src/setup.c b/src/setup.c
    index 97da20940..7158d3c53 100644
    a b load_setup (void) 
    11781178        mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_store", ""); 
    11791179    clipboard_paste_path = 
    11801180        mc_config_get_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste", ""); 
     1181    clipboard_force_no_display = 
     1182        mc_config_get_bool (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_force_no_display", FALSE); 
    11811183} 
    11821184 
    11831185/* --------------------------------------------------------------------------------------------- */ 
    save_setup (gboolean save_options, gboolean save_panel_options) 
    12301232                              clipboard_store_path); 
    12311233        mc_config_set_string (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_paste", 
    12321234                              clipboard_paste_path); 
     1235        mc_config_set_bool (mc_global.main_config, CONFIG_MISC_SECTION, "clipboard_force_no_display", 
     1236                            clipboard_force_no_display); 
    12331237 
    12341238        tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE); 
    12351239        ret = mc_config_save_to_file (mc_global.main_config, tmp_profile, NULL);