How to Tell Whether I'm in a Screen

How can I tell whether I'm in a screen?

Check $STY. If it's null, you're on a "real" terminal. If it contains anything, it's the name of the screen you're in.

If you are not in screen:

eric@dev ~ $ echo $STY
eric@dev ~ $

If you are in screen:

eric@dev ~ $ echo $STY
2026.pts-0.ip-10-0-1-71

How can I detect whether the mouse is in a certain part of the screen?

You can look at window.innerHeight and window.innerWidth. They return the viewport dimensions.

You may have better luck with if-else logic like this.

if (event.clientY < window.innerHeight / 2) {
// it's in the upper half
} else {
// it's in the lower half
}

How can I tell if my tmux screen is the one visible?

You can use tmux display-message with $TMUX_PANE to show whether the current pane is active/inactive:

$ TMUX_STATUS=$( tmux display-message -p -t $TMUX_PANE -F '#F' )
$ [[ "$TMUX_STATUS" == '*' ]] && echo "window is active"
window is active

Firstly, $TMUX_PANE is an environment variable exported by tmux which contains tmux's internal pane ID for the given shell.

The display-message -p command prints its output to STDOUT.

The -t $TMUX_PANE argument uses the $TMUX_PANE variable to query a specific pane (the current one, in this instance).

Finally, -f '#F' tells tmux to print only the "Current window flag" (Refer to the tmux man page, which has a list of character sequences under status-left).

AFAIK, these values are:

*, for the currently active window

-, for the previously selected window

And an empty string for windows which are neither active, nor "previous".

You'll need to poll tmux periodically from inside your program to determine whether focus has changed.

How to check if monitor is on or off

This is certainly not possible in cross platform Java, and to be honest isn't really possible in a reliable sense even if we resort to native code.

The (non-reliable) way to do this natively for Windows would be to use GetDevicePowerState - find it in kernel32.dll. However, from experiments I did using this function a while back I can say it definitely doesn't work with every monitor, and obviously even if this was reliable it would be a Windows-only solution.

If you do want to go down this route bearing in mind the above limitations, then use MonitorFromPoint to grab the handle to the primary monitor (pass in a 0,0 as the point and use the MONITOR_DEFAULTTOPRIMARY flag.)

Difference between screen flags -r and -x

-r attaches a detached session, while -x attaches an attached session without detaching it, so it runs in both the places at the same time. Another useful option combination is -d -r which detaches a session if needed first and then reattaches it.



Related Topics



Leave a reply



Submit