fune/widget/gtk/WidgetUtilsGtk.h
stransky 075294349b Bug 1904424 [Linux/X11] Don't steal focus on X11 r=emilio a=RyanVM
The patch comes from https://gitlab.com/redhat/centos-stream/rpms/firefox/-/merge_requests/94

Firefox isn't currently handling window focusing right on X11... There's a few problems:

If no startup id is provided, it tries to get user time from g_get_monotonic_time when there's no guarantee that timestamp is synchronized or even in a compatible unit. This merge request addressed that by dropping the code that uses g_get_monotonic_time entirely, and instead adding a heuristic to synthesize a startup id based on the time of the last user interaction on the display. This makes an assumption that firefox was started as a result of user interaction, which might not always hold true, but it's more likely than not, and is basically the same assumption firefox is already making by trying to use a timestamp of "now" (g_get_monotonic_time) when focusing the window.

If a startup id is provided, it fails to tell gtk to use it when focusing the window because it calls gtk_window_present_with_time with some other random timestamp instead of passing GDK_CURRENT_TIME (which is the magic value that means "use startup id for timestamp"). This commit tries to detect when a startup id is available, and the display is X11, and if so use a timestamp of GDK_CURRENT_TIME.

Differential Revision: https://phabricator.services.mozilla.com/D217174
2024-08-01 13:24:14 +00:00

89 lines
2.5 KiB
C++

/* -*- 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/. */
#ifndef WidgetUtilsGtk_h__
#define WidgetUtilsGtk_h__
#include "nsString.h"
#include "nsTArray.h"
#include "mozilla/MozPromise.h"
#include <stdint.h>
typedef struct _GdkDisplay GdkDisplay;
typedef struct _GdkDevice GdkDevice;
typedef struct _GError GError;
typedef union _GdkEvent GdkEvent;
class nsWindow;
namespace mozilla::widget {
class WidgetUtilsGTK {
public:
/* See WidgetUtils::IsTouchDeviceSupportPresent(). */
static int32_t IsTouchDeviceSupportPresent();
};
bool IsMainWindowTransparent();
bool GdkIsWaylandDisplay(GdkDisplay* display);
bool GdkIsX11Display(GdkDisplay* display);
bool GdkIsWaylandDisplay();
bool GdkIsX11Display();
bool IsXWaylandProtocol();
GdkDevice* GdkGetPointer();
// Sets / returns the last mouse press event we processed.
void SetLastMousePressEvent(GdkEvent*);
GdkEvent* GetLastMousePressEvent();
// Return the snap's instance name, or null when not running as a snap.
const char* GetSnapInstanceName();
bool IsRunningUnderSnap();
bool IsRunningUnderFlatpak();
bool IsPackagedAppFileExists();
inline bool IsRunningUnderFlatpakOrSnap() {
return IsRunningUnderFlatpak() || IsRunningUnderSnap();
}
enum class PortalKind {
FilePicker,
MimeHandler,
Settings,
Location,
OpenUri,
};
bool ShouldUsePortal(PortalKind);
// Tries to get a descriptive identifier for the desktop environment that the
// program is running under. Always normalized to lowercase.
// See the implementation for the different environment variables and desktop
// information we try to use.
//
// If we can't find a reasonable environment, the empty string is returned.
const nsCString& GetDesktopEnvironmentIdentifier();
bool IsGnomeDesktopEnvironment();
bool IsKdeDesktopEnvironment();
// Parse text/uri-list
nsTArray<nsCString> ParseTextURIList(const nsACString& data);
using FocusRequestPromise = MozPromise<nsCString, bool, false>;
RefPtr<FocusRequestPromise> RequestWaylandFocusPromise();
bool IsCancelledGError(GError* aGError);
#if defined(MOZ_X11)
// Used by startup notifications
nsCString SynthesizeStartupToken();
void FindLatestUserTime(GdkDisplay* aDisplay, uintptr_t aWindow,
unsigned long* aLatestTime);
#endif
} // namespace mozilla::widget
#endif // WidgetUtilsGtk_h__