diff --git a/custom-prompt/custom-prompt.cc b/custom-prompt/custom-prompt.cc index e2b45a2..6afbc18 100644 --- a/custom-prompt/custom-prompt.cc +++ b/custom-prompt/custom-prompt.cc @@ -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); diff --git a/custom-prompt/get_active_wid_linux.c b/custom-prompt/get_active_wid_linux.c index d5c77d2..d1cbb9f 100644 --- a/custom-prompt/get_active_wid_linux.c +++ b/custom-prompt/get_active_wid_linux.c @@ -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);