/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// We avoid linking gdk_*_display_get_type directly in order to avoid a runtime // dependency on GTK built with both backends. Other X11- and Wayland-specific // functions get stubbed out by libmozgtk and crash when called, but those // should only be called when the matching backend is already in use.
private:
xdg_activation_token_v1* mXdgToken;
RefPtr<FocusRequestPromise::Private> mTransferPromise;
guint mActivationTimeoutID; // Reject FocusRequestPromise if we don't get XDG token in 0.5 sec. static constexpr int sActivationTimeout = 500;
};
// Failed to get token in time static gboolean token_failed(gpointer data) {
UniquePtr<XDGTokenRequest> request(static_cast<XDGTokenRequest*>(data));
request->Cancel(); returnfalse;
}
// We've got activation token from Wayland compositor so it's time to use it. staticvoid token_done(gpointer data, struct xdg_activation_token_v1* provider, constchar* tokenID) {
UniquePtr<XDGTokenRequest> request(static_cast<XDGTokenRequest*>(data));
request->SetTokenID(tokenID);
}
// Getting a reliable identifier is quite tricky. We try to use the standard // XDG_CURRENT_DESKTOP environment first, _NET_WM_NAME later, and a set of // legacy / non-standard environment variables otherwise. // // Documentation for some of those can be found in: // // https://wiki.archlinux.org/title/Environment_variables#Examples // https://wiki.archlinux.org/title/Xdg-utils#Environment_variables const nsCString& GetDesktopEnvironmentIdentifier() { staticconst nsDependentCString sIdentifier = [] {
nsCString ident = [] { auto Env = [](constchar* aKey) -> constchar* { constchar* v = getenv(aKey); return v && *v ? v : nullptr;
}; if (constchar* currentDesktop = Env("XDG_CURRENT_DESKTOP")) { return nsCString(currentDesktop);
} if (auto wm = GetWindowManagerName(); !wm.IsEmpty()) { return wm;
} if (constchar* sessionDesktop = Env("XDG_SESSION_DESKTOP")) { // This is not really standardized in freedesktop.org, but it is // documented here, and should be set in systemd systems. // https://www.freedesktop.org/software/systemd/man/pam_systemd.html#%24XDG_SESSION_DESKTOP return nsCString(sessionDesktop);
} // We try first the DE-specific variables, then SESSION_DESKTOP, to match // the documented order in: // https://wiki.archlinux.org/title/Xdg-utils#Environment_variables if (getenv("GNOME_DESKTOP_SESSION_ID")) { return nsCString("gnome"_ns);
} if (getenv("KDE_FULL_SESSION")) { return nsCString("kde"_ns);
} if (getenv("MATE_DESKTOP_SESSION_ID")) { return nsCString("mate"_ns);
} if (getenv("LXQT_SESSION_CONFIG")) { return nsCString("lxqt"_ns);
} if (constchar* desktopSession = Env("DESKTOP_SESSION")) { // Try the legacy DESKTOP_SESSION as a last resort. return nsCString(desktopSession);
} return nsCString();
}();
ToLowerCase(ident); // Intentionally put into a ToNewCString copy, rather than just making a // static nsCString to avoid leakchecking errors, since we really want to // leak this string. return nsDependentCString(ToNewCString(ident), ident.Length());
}(); return sIdentifier;
}
if (XQueryTree(xDisplay, aWindow, &rootReturn, &parentReturn, &children,
&numberOfChildren)) { for (unsignedint i = 0; i < numberOfChildren; i++) {
userTime = GetWindowUserTime(aDisplay, children[i]); if (userTime > *aLatestTime) {
*aLatestTime = userTime;
}
FindLatestUserTime(aDisplay, children[i], aLatestTime);
}
XFree(children);
}
}
// Assume we're started from user interaction and infer user time if its missing
nsCString SynthesizeStartupToken() { unsignedlong latestUserTime = 0;
FindLatestUserTime(gdk_display_get_default(),
GDK_WINDOW_XID(gdk_get_default_root_window()),
&latestUserTime);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.