Skip to content

Replace hidecursorinactive with hook commands - #1763

Merged
joelim-work merged 2 commits into
gokcehan:masterfrom
joelim-work:focusreport
Jul 1, 2024
Merged

joelim-work merged 2 commits into
gokcehan:masterfrom
joelim-work:focusreport

Conversation

@joelim-work

@joelim-work joelim-work commented Jun 28, 2024 •

Copy link
Copy Markdown
Contributor

Related issues

Description

This PR replaces the hidecursorinactive option introduced in #965 with the more generic on-focus-gained and on-focus-lost hook commands, allowing for greater customization for when the terminal gains or loses focus. This also properly solves #1673 by providing an option focusreport to explictly control terminal focus reporting only enabling terminal focus reporting if either of the hook commands are defined.

Examples

Hide the cursors completely when the terminal loses focus (same effect as set hidecursorinactive true):

# hook command which is invoked when the terminal gains focus
cmd on-focus-gained :{{
    set cursorparentfmt "\033[7m"
    set cursoractivefmt "\033[7m"
    set cursorpreviewfmt "\033[4m"
}}

# hook command which is invoked when the terminal loses focus
cmd on-focus-lost :{{
    set cursorparentfmt ""
    set cursoractivefmt ""
    set cursorpreviewfmt ""
}}

# set initial values upon startup
on-focus-gained

Dim the cursors when the terminal loses focus:

# hook command which is invoked when the terminal gains focus
cmd on-focus-gained :{{
    set cursorparentfmt "\033[7m"
    set cursoractivefmt "\033[7m"
    set cursorpreviewfmt "\033[4m"
}}

# hook command which is invoked when the terminal loses focus
cmd on-focus-lost :{{
    set cursorparentfmt "\033[7;2m"
    set cursoractivefmt "\033[7;2m"
    set cursorpreviewfmt "\033[4;2m"
}}

# set initial values upon startup
on-focus-gained

@DusanLesan

Copy link
Copy Markdown
Contributor

Very nice solution for cursorparentfmtinactive. Would it be possible to avoid explicitly setting focusreport by checking if the user has either on-focus-gained or on-focus-lost set?

@joelim-work

joelim-work commented Jun 30, 2024 •

Copy link
Copy Markdown
Contributor Author

Would it be possible to avoid explicitly setting focusreport by checking if the user has either on-focus-gained or on-focus-lost set?

I think this is debatable. On one hand it's nice to avoid adding yet another option (lf has too many), but on the other hand it also makes the code rather 'clever' (one can argue that cmd should only define commands, not do anything else like enabling/disabling focus reporting).

For now I think I will go with your suggestion as it isn't too complex to implement.

@DusanLesan

Copy link
Copy Markdown
Contributor

I think this is a better way than needing to enable focusreport. Similar to on-redraw, the user can extend app functionality just by adding the appropriate function. In the case of focus hooks, the app can simply skip observing these events if the user has not set callbacks. This way, the user does not need to worry about the app's inner behavior, as the app can determine if it is needed or not by itself.

@joelim-work

Copy link
Copy Markdown
Contributor Author

No worries, I have already implemented this in 6fa8aee.

@joelim-work
joelim-work merged commit e9faf96 into gokcehan:master Jul 1, 2024
@joelim-work
joelim-work deleted the focusreport branch July 1, 2024 02:17
@joelim-work joelim-work added this to the r33 milestone Jul 1, 2024
@joelim-work joelim-work added the breaking Pull requests that introduce breaking changes label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Pull requests that introduce breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: highlighting of cursors when inactive r32 prints ^[[I or I in libvte-based terminals

2 participants