Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "gnome-gradienttopbar",
"title": "Gradient Top Bar",
"description": "Makes GNOME's panel's background gradient. You can edit the colour scheme from the extension's settings in Gnome 45.",
"version": "22",
"version": "23-rc",
"engines": {
"gnome": ">=47"
},
Expand Down
4 changes: 4 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const MAXIMIZED_COLORS = 'maximized-colors';
* @returns {Object} The complete configuration object
*/
export const getConfig = settings => {
const maximizationType = settings.get_string('maximization-type');
const maximizedBehavior = settings.get_string(MAXIMIZED_BEHAVIOR);
const colors = settings.get_value(COLORS).deep_unpack();
const gradientDirection = settings.get_string(GRADIENT_DIRECTION);
Expand All @@ -28,6 +29,7 @@ export const getConfig = settings => {

return {
maximizedBehavior,
maximizationType,
gradientDirection,
colors: {
start: colors[0],
Expand Down Expand Up @@ -152,6 +154,7 @@ export const saveMaximizedColors = (settings, startRgba, endRgba) => {
export const attachSettingsListeners = (settings, listener) => {
settings.connect(`changed::${GRADIENT_DIRECTION}`, listener);
settings.connect(`changed::${MAXIMIZED_BEHAVIOR}`, listener);
settings.connect('changed::maximization-type', listener);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix constant and we can do a loop here.

settings.connect(`changed::${COLORS}`, listener);
settings.connect(`changed::${MAXIMIZED_COLORS}`, listener);
settings.connect(`changed::${MAXIMIZED_GRADIENT_DIRECTION}`, listener);
Expand All @@ -166,6 +169,7 @@ export const attachSettingsListeners = (settings, listener) => {
export const detachSettingsListeners = (settings, listener) => {
settings.disconnect(`changed::${GRADIENT_DIRECTION}`, listener);
settings.disconnect(`changed::${MAXIMIZED_BEHAVIOR}`, listener);
settings.disconnect('changed::maximization-type', listener);
settings.disconnect(`changed::${COLORS}`, listener);
settings.disconnect(`changed::${MAXIMIZED_COLORS}`, listener);
settings.disconnect(`changed::${MAXIMIZED_GRADIENT_DIRECTION}`, listener);
Expand Down
8 changes: 8 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ export const MAXIMIZED_BEHAVIOR = {
APPLY_STYLE: 'apply-style'
};

// Maximization type constants
export const MAXIMIZATION_TYPE = {
BOTH: 'both',
VERTICAL: 'vertical',
HORIZONTAL: 'horizontal',
ANY: 'any'
};

// Gradient directions
export const GRADIENT_DIRECTION = {
VERTICAL: 'vertical',
Expand Down
62 changes: 47 additions & 15 deletions src/events/windowEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { overview } from 'resource:///org/gnome/shell/ui/main.js';

import EventManager from './eventManager.js';
import { areSameState } from './states.js';
import { MAXIMIZATION_TYPE } from '../constants.js';

const { VERTICAL, BOTH } = Meta.MaximizeFlags;
const { VERTICAL, HORIZONTAL, BOTH } = Meta.MaximizeFlags;

const SIZE_CHANGE_EVENT = 'size-changed';
const WORKSPACE_CHANGE_EVENT = 'workspace-switched';
Expand All @@ -24,26 +25,37 @@ const OVERVIEW_HIDING = 'hiding';
// FIXME: this causes the overview to close on login
const isDesktopIconsNG = window => window.customJS_ding !== undefined; // this is to ignore "Desktop Icons NG"'s window hacks

// Check if window is full screen or monitor sized
const isFullScreen = window => window.is_monitor_sized() || window.is_screen_sized();

/**
* Determines if a window is maximized or full-screen
*
* @param {Meta.Window} window - The window to check
* @param {string} maximizationType - Maximization type definition
* @returns {boolean} True if the window is maximized or full-screen
*/
const isMaximized = window => {
const isMaximized = (window, maximizationType = MAXIMIZATION_TYPE.BOTH) => {
// Ignore Desktop Icons NG windows
if (isDesktopIconsNG(window))
return false;


// Check if window is full-screen
if (window.is_monitor_sized() || window.is_screen_sized())
return true;


// Check if window is maximized (either vertically or both dimensions)
const maximizeFlags = window.get_maximized();
return [BOTH, VERTICAL].includes(maximizeFlags);
const windowMaximizeState = window.get_maximized();

switch (maximizationType) {
case MAXIMIZATION_TYPE.BOTH:
return windowMaximizeState === BOTH || isFullScreen(window);
case MAXIMIZATION_TYPE.VERTICAL:
return windowMaximizeState === VERTICAL || windowMaximizeState === BOTH;
case MAXIMIZATION_TYPE.HORIZONTAL:
return windowMaximizeState === HORIZONTAL || windowMaximizeState === BOTH;
case MAXIMIZATION_TYPE.ANY:
return windowMaximizeState === VERTICAL ||
windowMaximizeState === HORIZONTAL ||
windowMaximizeState === BOTH || isFullScreen(window);
default:
return windowMaximizeState === BOTH;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the default case

}
};

/**
Expand All @@ -70,6 +82,7 @@ export default class WindowEvents {
this.workspace = null;
this.inOverview = false;
this.maximizedWindows = new Set();
this.maximizationType = MAXIMIZATION_TYPE.BOTH; // Default value
this.lastState = null;
}

Expand All @@ -82,6 +95,23 @@ export default class WindowEvents {
this.stateChangeCallback = callback;
}

setMaximizationType(type) {
this.maximizationType = type;
this.forceStateUpdate();
}

forceStateUpdate() {
// Update the maximized windows set based on the current maximization type
this.maximizedWindows = this.getMaximizedWindowIds();

// Force a state change emission
this.stateChangeCallback({
maximizedWindows: this.maximizedWindows,
currentWorkspace: this.workspace,
inOverview: this.inOverview
});
}

/**
* Gets the current window state
*
Expand Down Expand Up @@ -130,7 +160,7 @@ export default class WindowEvents {
* @param {Meta.Window} window - The window that changed size
*/
const onWindowSizeChange = window => {
if (isMaximized(window))
if (isMaximized(window, this.maximizationType))
this.maximizedWindows.add(window.get_id());
else
this.maximizedWindows.delete(window.get_id());
Expand Down Expand Up @@ -179,7 +209,7 @@ export default class WindowEvents {
);
}

if (isMaximized(window))
if (isMaximized(window, this.maximizationType))
this.maximizedWindows.add(window.get_id());

this.eventManager.attachWindowEventOnce(
Expand Down Expand Up @@ -209,11 +239,13 @@ export default class WindowEvents {
*/
const onWindowRaise = (_, windowActor) => {
const window = windowActor.get_meta_window();
if (isMaximized(window))
if (isMaximized(window, this.maximizationType))
this.maximizedWindows.add(window.get_id());
this.emitStateChange();
};

const forceStateChangeEmission = () => emitStateChange(true);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wtf is this


this.workspace = this.workspaceManager.get_active_workspace();

// TODO: what if the window starts as maximized dimensions but is not "snapped"?
Expand Down Expand Up @@ -310,7 +342,7 @@ export default class WindowEvents {
return new Set(
this.display
.list_all_windows()
.filter(isMaximized)
.filter(window => isMaximized(window, this.maximizationType))

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bring in the ismaximized in scope so it can read this.

.map(window => window.get_id())
);
}
Expand Down
21 changes: 16 additions & 5 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export default class GradientTopBar extends Extension {
const config = getConfig(settings);
applyGradientStyle(config, this.path);

// For other behaviors, we need to track window states

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a check if we're using a simple gradient and return if so.

if (!this.windowEvents) {
// If window events were not initialized, initialize them now
this.initializeWindowEvents();
}
// Update maximization type if it changed
if (this.windowEvents)
this.windowEvents.setMaximizationType(config.maximizationType);

const maximizedBehavior = getMaximizedBehavior(settings);

// If set to keep-gradient, disable window events to save resources
Expand All @@ -34,12 +43,9 @@ export default class GradientTopBar extends Extension {
return;
}

// For other behaviors, we need to track window states
if (!this.windowEvents) {
// If window events were not initialized, initialize them now
this.initializeWindowEvents();
}
this.windowEvents.enable();

// Force update to apply the current behavior
this.windowEvents.forceStateUpdate();
};
}
Expand All @@ -62,6 +68,10 @@ export default class GradientTopBar extends Extension {
global.window_manager,
global.get_workspace_manager()
);
const config = getConfig(this._settings);

// Set the maximization type from settings
this.windowEvents.setMaximizationType(config.maximizationType);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be there wtf


this.windowEvents.setStateChangeCallback(
({ maximizedWindows, currentWorkspace, inOverview }) => {
Expand Down Expand Up @@ -134,6 +144,7 @@ export default class GradientTopBar extends Extension {
this.toggleGradient(false);
detachSettingsListeners(this._settings, this.onSettingsChanged);

this.windowEvents = null;
this.isEffectApplied = false;
this._settings = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"shell-version": ["47", "48"],
"url": "https://github.com/petar-v/gradienttopbar",
"version": 22,
"version": 23,
"gettext-domain": "org.pshow.gradienttopbar",
"settings-schema": "org.gnome.shell.extensions.org.pshow.gradienttopbar",
"hasPrefs": true
Expand Down
Binary file modified src/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@
<value nick="keep-theme" value="1"/>
<value nick="apply-style" value="2"/>
</enum>
<enum id="org.gnome.shell.extensions.org.pshow.gradienttopbar.MaximizationType">
<value nick="both" value="0"/>
<value nick="vertical" value="1"/>
<value nick="horizontal" value="2"/>
<value nick="any" value="3"/>
</enum>
<schema id="org.gnome.shell.extensions.org.pshow.gradienttopbar" path="/org/gnome/shell/extensions/org/pshow/gradienttopbar/">
<key name="maximized-behavior" enum="org.gnome.shell.extensions.org.pshow.gradienttopbar.MaximizedBehavior">
<default>'keep-gradient'</default>
<summary>Behavior when windows are maximized</summary>
<description>Determines what style to apply to the top bar when there is a maximized window: keep the normal gradient, use the default theme, or apply a custom style.</description>
</key>
<key name="maximization-type" enum="org.gnome.shell.extensions.org.pshow.gradienttopbar.MaximizationType">
<default>'both'</default>
<summary>Definition of a maximized window</summary>
<description>Determines what constitutes a maximized window: both horizontally and vertically maximized, only vertically maximized, only horizontally maximized, or any of these.</description>
</key>
<key name="colors" type="as">
<default>["rgba(0, 0, 0, 1)", "rgba(0, 0, 0, 0)"]</default>
<summary>Array of the gradient colours</summary>
Expand Down
Loading