Skip to content

Commit

Permalink
[mouse] Create or delete ~/.elinks/mouse.lock file while changing ui.…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
rkd77 committed Jan 2, 2022
1 parent c388d2e commit 88d9704
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/config/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
#include <ctype.h>
#include <string.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "elinks.h"

#include "bfu/dialog.h"
#include "cache/cache.h"
#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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 },
};
Expand Down
3 changes: 2 additions & 1 deletion src/terminal/kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
21 changes: 20 additions & 1 deletion src/terminal/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "elinks.h"

#include "config/home.h"
#include "config/options.h"
#include "dialogs/status.h"
#include "intl/libintl.h"
Expand Down Expand Up @@ -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)
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions src/terminal/mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ struct interlink_event;
struct itrm;
struct session;

extern int mouse_enabled;

/* The mouse reporting button byte looks like:
*
* -ss??bbb
Expand Down

0 comments on commit 88d9704

Please sign in to comment.