зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1539998 [Linux] Implement nsLookAndFeel::GetTitlebarAction() r=emilio
Get titlebar actions from gtk-titlebar-double-click / gtk-titlebar-middle-click gsettings keys and monitor key changes and export it as nsLookAndFeel::GetTitlebarAction(). Differential Revision: https://phabricator.services.mozilla.com/D199882
This commit is contained in:
Родитель
49a86a5ea8
Коммит
44348f2d89
|
@ -493,6 +493,28 @@ class LookAndFeel {
|
|||
*/
|
||||
static bool DrawInTitlebar();
|
||||
|
||||
enum class TitlebarAction {
|
||||
None,
|
||||
WindowLower,
|
||||
WindowMenu,
|
||||
WindowMinimize,
|
||||
WindowMaximize,
|
||||
WindowMaximizeToggle,
|
||||
// We don't support more actions (maximize-horizontal, maximize-vertical,..)
|
||||
// as they're implemented as part of Wayland gtk_surface1 protocol
|
||||
// which is not accessible to us.
|
||||
};
|
||||
|
||||
enum class TitlebarEvent {
|
||||
Double_Click,
|
||||
Middle_Click,
|
||||
};
|
||||
|
||||
/**
|
||||
* Get system defined action for titlebar events.
|
||||
*/
|
||||
static TitlebarAction GetTitlebarAction(TitlebarEvent aEvent);
|
||||
|
||||
/**
|
||||
* The millisecond to mask password value.
|
||||
* This value is only valid when GetEchoPassword() returns true.
|
||||
|
|
|
@ -189,6 +189,9 @@ nsLookAndFeel::nsLookAndFeel() {
|
|||
"notify::gtk-menu-popup-delay"_ns,
|
||||
// Affects DragThresholdX/Y
|
||||
"notify::gtk-dnd-drag-threshold"_ns,
|
||||
// Affects titlebar actions loaded at moz_gtk_refresh().
|
||||
"notify::gtk-titlebar-double-click"_ns,
|
||||
"notify::gtk-titlebar-middle-click"_ns,
|
||||
};
|
||||
|
||||
GtkSettings* settings = gtk_settings_get_default();
|
||||
|
@ -1620,6 +1623,36 @@ void nsLookAndFeel::InitializeGlobalSettings() {
|
|||
*pos = i;
|
||||
}
|
||||
}
|
||||
|
||||
struct actionMapping {
|
||||
TitlebarAction action;
|
||||
char name[100];
|
||||
} ActionMapping[] = {
|
||||
{TitlebarAction::None, "none"},
|
||||
{TitlebarAction::WindowLower, "lower"},
|
||||
{TitlebarAction::WindowMenu, "menu"},
|
||||
{TitlebarAction::WindowMinimize, "minimize"},
|
||||
{TitlebarAction::WindowMaximize, "maximize"},
|
||||
{TitlebarAction::WindowMaximizeToggle, "toggle-maximize"},
|
||||
};
|
||||
|
||||
auto GetWindowAction = [&](const char* eventName) -> TitlebarAction {
|
||||
gchar* action = nullptr;
|
||||
g_object_get(settings, eventName, &action, nullptr);
|
||||
if (!action) {
|
||||
return TitlebarAction::None;
|
||||
}
|
||||
auto free = mozilla::MakeScopeExit([&] { g_free(action); });
|
||||
for (auto const mapping : ActionMapping) {
|
||||
if (!strncmp(action, mapping.name, strlen(mapping.name))) {
|
||||
return mapping.action;
|
||||
}
|
||||
}
|
||||
return TitlebarAction::None;
|
||||
};
|
||||
|
||||
mDoubleClickAction = GetWindowAction("gtk-titlebar-double-click");
|
||||
mMiddleClickAction = GetWindowAction("gtk-titlebar-middle-click");
|
||||
}
|
||||
|
||||
void nsLookAndFeel::ConfigureFinalEffectiveTheme() {
|
||||
|
@ -2233,6 +2266,12 @@ bool nsLookAndFeel::GetEchoPasswordImpl() { return false; }
|
|||
|
||||
bool nsLookAndFeel::GetDefaultDrawInTitlebar() { return sCSDAvailable; }
|
||||
|
||||
nsXPLookAndFeel::TitlebarAction nsLookAndFeel::GetTitlebarAction(
|
||||
TitlebarEvent aEvent) {
|
||||
return aEvent == TitlebarEvent::Double_Click ? mDoubleClickAction
|
||||
: mMiddleClickAction;
|
||||
}
|
||||
|
||||
void nsLookAndFeel::GetThemeInfo(nsACString& aInfo) {
|
||||
aInfo.Append(mSystemTheme.mName);
|
||||
aInfo.Append(" / ");
|
||||
|
|
|
@ -42,6 +42,9 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
|
||||
bool GetDefaultDrawInTitlebar() override;
|
||||
|
||||
nsXPLookAndFeel::TitlebarAction GetTitlebarAction(
|
||||
TitlebarEvent aEvent) override;
|
||||
|
||||
void GetThemeInfo(nsACString&) override;
|
||||
|
||||
static const nscolor kBlack = NS_RGB(0, 0, 0);
|
||||
|
@ -179,6 +182,8 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
int32_t mCSDMaximizeButtonPosition = 0;
|
||||
int32_t mCSDMinimizeButtonPosition = 0;
|
||||
int32_t mCSDCloseButtonPosition = 0;
|
||||
TitlebarAction mDoubleClickAction = TitlebarAction::None;
|
||||
TitlebarAction mMiddleClickAction = TitlebarAction::None;
|
||||
|
||||
RefPtr<GtkCssProvider> mRoundedCornerProvider;
|
||||
void UpdateRoundedBottomCornerStyles();
|
||||
|
|
|
@ -1495,6 +1495,11 @@ bool LookAndFeel::DrawInTitlebar() {
|
|||
return nsLookAndFeel::GetInstance()->GetDefaultDrawInTitlebar();
|
||||
}
|
||||
|
||||
LookAndFeel::TitlebarAction LookAndFeel::GetTitlebarAction(
|
||||
TitlebarEvent aEvent) {
|
||||
return nsLookAndFeel::GetInstance()->GetTitlebarAction(aEvent);
|
||||
}
|
||||
|
||||
void LookAndFeel::GetThemeInfo(nsACString& aOut) {
|
||||
nsLookAndFeel::GetInstance()->GetThemeInfo(aOut);
|
||||
}
|
||||
|
|
|
@ -57,6 +57,10 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel {
|
|||
|
||||
virtual bool GetDefaultDrawInTitlebar() { return true; }
|
||||
|
||||
virtual TitlebarAction GetTitlebarAction(TitlebarEvent aEvent) {
|
||||
return TitlebarAction::None;
|
||||
}
|
||||
|
||||
static bool LookAndFeelFontToStyle(const LookAndFeelFont&, nsString& aName,
|
||||
gfxFontStyle&);
|
||||
static LookAndFeelFont StyleToLookAndFeelFont(const nsAString& aName,
|
||||
|
|
Загрузка…
Ссылка в новой задаче