Skip to content

Commit

Permalink
[ikhal] add option to disable mouse, fixes pimutils#1289
Browse files Browse the repository at this point in the history
This is done by passing the `handle_mouse` Boolean argument to urwid's
main loop (currently unused). By default, the mouse remains enabled
(see `khal.spec`). Mouse can be disabled either by setting
`enable_mouse = False` in the `[default]` section of khal's config
file, or by passing the `--no-mouse` flag to the `khal interactive` or
`ikhal` click commands.
  • Loading branch information
choucavalier committed Sep 16, 2023
1 parent 0682f0d commit 01d8d2e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ env/
venv/
.hypothesis/
.python-version
.dmypy.json
1 change: 1 addition & 0 deletions khal.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ monthdisplay = firstday
default_calendar = home
timedelta = 2d # the default timedelta that list uses
highlight_event_days = True # the default is False
enable_mouse = True # mouse is enabled by default in interactive mode
16 changes: 14 additions & 2 deletions khal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def multi_calendar_option(f):
return d(a(f))


def no_mouse_option(f):
o = click.option('--no-mouse', is_flag=True,
help='Disable mouse in interactive UI')
return o(f)


def _select_one_calendar_callback(ctx, option, calendar):
if isinstance(calendar, tuple):
if len(calendar) > 1:
Expand Down Expand Up @@ -480,9 +486,12 @@ def isatty(_file):

@cli.command()
@multi_calendar_option
@no_mouse_option
@click.pass_context
def interactive(ctx, include_calendar, exclude_calendar):
def interactive(ctx, include_calendar, exclude_calendar, no_mouse):
'''Interactive UI. Also launchable via `ikhal`.'''
if no_mouse:
ctx.obj['conf']['default']['enable_mouse'] = False
controllers.interactive(
build_collection(
ctx.obj['conf'],
Expand All @@ -494,10 +503,13 @@ def interactive(ctx, include_calendar, exclude_calendar):
@click.command()
@global_options
@multi_calendar_option
@no_mouse_option
@click.pass_context
def interactive_cli(ctx, config, include_calendar, exclude_calendar):
def interactive_cli(ctx, config, include_calendar, exclude_calendar, no_mouse):
'''Interactive UI. Also launchable via `khal interactive`.'''
prepare_context(ctx, config)
if no_mouse:
ctx.obj['conf']['default']['enable_mouse'] = False
controllers.interactive(
build_collection(
ctx.obj['conf'],
Expand Down
4 changes: 4 additions & 0 deletions khal/settings/khal.spec
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ default_event_duration = timedelta(default='1d')
# Define the default duration for an event ('khal new' only)
default_dayevent_duration = timedelta(default='1h')

# Whether the mouse should be enabled in interactive mode ('khal interactive' and
# 'ikhal' only)
enable_mouse = boolean(default=True)


# The view section contains configuration options that effect the visual appearance
# when using khal and ikhal.
Expand Down
7 changes: 6 additions & 1 deletion khal/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,12 @@ def emit(self, record):
palette = _add_calendar_colors(
getattr(colors, pane._conf['view']['theme']), pane.collection)
loop = urwid.MainLoop(
frame, palette, unhandled_input=frame.on_key_press, pop_ups=True)
widget=frame,
palette=palette,
unhandled_input=frame.on_key_press,
pop_ups=True,
handle_mouse=pane._conf['default']['enable_mouse'],
)
frame.loop = loop

def redraw_today(loop, pane, meta=None):
Expand Down

0 comments on commit 01d8d2e

Please sign in to comment.