Skip to content

Commit

Permalink
Linux no-display fix (#48)
Browse files Browse the repository at this point in the history
* Linux: do not crash if no display server is running
* Updated documentation of `get_active_wid`
  • Loading branch information
tfpf authored Aug 16, 2024
1 parent 5a3f092 commit 806517c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion custom-prompt/custom-prompt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ void Interval::print_long(std::ostream& ostream) const
/******************************************************************************
* Get the ID of the currently-focused window.
*
* @return Active window ID.
* @return Active window ID. On Linux, if there is no X display running, 0 is
* returned. Likewise, on macOS, if no topmost window is found, 0 is returned.
*****************************************************************************/
extern "C" long long unsigned get_active_wid(void);

Expand Down
5 changes: 5 additions & 0 deletions custom-prompt/get_active_wid_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
long long unsigned get_active_wid(void)
{
Display* display = XOpenDisplay(NULL);
if (display == NULL)
{
return 0;
}

Window root_window = DefaultRootWindow(display);
Atom property = XInternAtom(display, "_NET_ACTIVE_WINDOW", False);

Expand Down

0 comments on commit 806517c

Please sign in to comment.