1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

[mouse] Create or delete ~/.elinks/mouse.lock file while changing ui.mouse_disable option. Refs #137

There is no good way to inform slave elinks instances about options. So, for mouse there is a workaround.
Note, If you set ui.mouse_disable = 1 in elinks.conf manually, to get effect on 2nd ELinks instance,
you must also touch ~/.elinks/mouse.lock . Changes via option manager delete or create this file automatically.
This commit is contained in:
Witold Filipczyk 2022-01-02 15:17:53 +01:00
parent c388d2e397
commit 88d9704e11
4 changed files with 47 additions and 2 deletions

View File

@ -7,6 +7,10 @@
#include <ctype.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "elinks.h"
#include "bfu/dialog.h"
@ -14,6 +18,7 @@
#include "config/conf.h"
#include "config/dialogs.h"
#include "config/domain.h"
#include "config/home.h"
#include "config/options.h"
#include "config/opttypes.h"
#include "dialogs/status.h"
@ -872,6 +877,23 @@ change_hook_ui_double_esc(struct session *ses, struct option *current, struct op
return 0;
}
static int
change_hook_ui_mouse_disable(struct session *ses, struct option *current, struct option *changed)
{
char *lock_filename = straconcat(empty_string_or_(elinks_home), "mouse.lock", (char *)NULL);
if (lock_filename) {
if (changed->value.number) {
creat(lock_filename, 0600);
} else {
unlink(lock_filename);
}
mem_free(lock_filename);
}
return 0;
}
/** Make option templates visible or invisible in the option manager.
* This is called once on startup, and then each time the value of the
* "config.show_template" option is changed.
@ -946,6 +968,7 @@ static const struct change_hook_info change_hooks[] = {
{ "terminal", change_hook_terminal },
{ "ui.double_esc", change_hook_ui_double_esc },
{ "ui.language", change_hook_language },
{ "ui.mouse_disable", change_hook_ui_mouse_disable },
{ "ui", change_hook_ui },
{ NULL, NULL },
};

View File

@ -174,8 +174,9 @@ send_init_sequence(int h, int altscreen)
write_sequence(h, INIT_ALT_SCREEN_SEQ);
}
#ifdef CONFIG_MOUSE
if (! get_opt_bool("ui.mouse_disable", NULL))
if (mouse_enabled) {
send_mouse_init_sequence(h);
}
#endif
write_sequence(h, INIT_BRACKETED_PASTE_SEQ);
}

View File

@ -24,6 +24,7 @@
#include "elinks.h"
#include "config/home.h"
#include "config/options.h"
#include "dialogs/status.h"
#include "intl/libintl.h"
@ -71,7 +72,7 @@ send_mouse_done_sequence(int h)
write_sequence(h, DONE_XWIN_MOUSE_SEQ);
}
static int mouse_enabled;
int mouse_enabled;
void
disable_mouse(void)
@ -84,12 +85,30 @@ disable_mouse(void)
mouse_enabled = 0;
}
static int
mouse_lock_exists(void)
{
char *lock_filename = straconcat(empty_string_or_(elinks_home), "mouse.lock", (char *) NULL);
int res = 0;
if (lock_filename) {
res = !access(lock_filename, F_OK);
mem_free(lock_filename);
}
return res;
}
void
enable_mouse(void)
{
if (get_opt_bool("ui.mouse_disable", NULL))
return;
if (mouse_lock_exists()) {
return;
}
if (mouse_enabled) return;
if (is_xterm()) send_mouse_init_sequence(get_output_handle());

View File

@ -9,6 +9,8 @@ struct interlink_event;
struct itrm;
struct session;
extern int mouse_enabled;
/* The mouse reporting button byte looks like:
*
* -ss??bbb