Skip to content

Commit 02f0ae8

Browse files
committed
Fix blurry overview preview windows in overview for gnome 43
1 parent 9ee56c8 commit 02f0ae8

File tree

5 files changed

+83
-14
lines changed

5 files changed

+83
-14
lines changed

@imports/misc/config.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare const PACKAGE_VERSION: string

src/effect/rounded_corners_effect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const RoundedCornersEffect = registerClass (
7777
border: {
7878
width: number
7979
color: [number, number, number, number]
80-
}
80+
} = { width: 0, color: [0, 0, 0, 0] }
8181
) {
8282
const actor = this.actor
8383

src/extension.ts

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { connections } from '@me/utils/connections'
2222
import { SchemasKeys, settings } from '@me/utils/settings'
2323
import { Services } from '@me/dbus/services'
2424
import { LinearFilterEffect } from '@me/effect/linear_filter_effect'
25+
import { RoundedCornersEffect } from '@me/effect/rounded_corners_effect'
2526
import { init_translations } from '@me/utils/i18n'
2627

2728
// types, which will be removed in output
@@ -182,11 +183,67 @@ export class Extension {
182183
}
183184
this.insert_child_below (shadow_clone, window_container)
184185

186+
// In Gnome 43, preview windows in overview will be blurry if there are
187+
// more than two workspaces using, We need add rounded corners to preview
188+
// window in overview manually to avoid blurry preview windows.
189+
type TypeRoundedCornersEffect =
190+
| InstanceType<typeof RoundedCornersEffect>
191+
| null
192+
| undefined
193+
let rounded_effect_of_window_actor: TypeRoundedCornersEffect = null
194+
if (UI.shell_version () >= 43) {
195+
// Name of rounded corners effect added to preview window
196+
const name = 'Rounded Corners Effect (Overview)'
197+
198+
// Disabled rounded corners of window temporarily when enter overview
199+
const window_actor: WindowActor = window.get_compositor_private ()
200+
rounded_effect_of_window_actor =
201+
self._rounded_corners_manager?.get_rounded_corners_effect (
202+
window_actor
203+
)
204+
rounded_effect_of_window_actor?.set_enabled (false)
205+
206+
// Add rounded corners effect to preview window actor
207+
first_child.add_effect_with_name (name, new RoundedCornersEffect ())
208+
209+
// Update uniform variables of rounded corners effect when size of
210+
// preview windows in overview changed.
211+
const c = connections.get ()
212+
c.connect (this, 'notify::width', () => {
213+
const rounded_effect_of_preview_window = first_child?.get_effect (
214+
name
215+
) as TypeRoundedCornersEffect
216+
if (!rounded_effect_of_preview_window) {
217+
return
218+
}
219+
220+
const buf_rect = window.get_buffer_rect ()
221+
const frame_rect = window.get_frame_rect ()
222+
const scaled = this.window_container.get_width () / frame_rect.width
223+
const x1 = (frame_rect.x - buf_rect.x) * scaled
224+
const y1 = (frame_rect.y - buf_rect.y) * scaled
225+
const x2 = x1 + frame_rect.width * scaled
226+
const y2 = y1 + frame_rect.height * scaled
227+
rounded_effect_of_preview_window.update_uniforms (
228+
scaled,
229+
settings ().global_rounded_corner_settings,
230+
{ x1, y1, x2, y2 }
231+
)
232+
})
233+
}
234+
185235
// Disconnect all signals when Window preview in overview is destroy
186-
const c = connections.get ()
187236
c.connect (this, 'destroy', () => {
237+
shadow_clone.destroy ()
188238
first_child?.clear_effects ()
189239
first_child = null
240+
241+
// Enabled rounded corners of window actor when leaving overview,
242+
// works for gnome 43.
243+
if (overview._overview.controls._workspacesDisplay._leavingOverview) {
244+
rounded_effect_of_window_actor?.set_enabled (true)
245+
}
246+
190247
c.disconnect_all (this)
191248
})
192249
}
@@ -384,7 +441,10 @@ const OverviewShadowActor = registerClass (
384441
: this._window_preview.get_allocation_box ()
385442

386443
// Meta.Window contain the all information about a window
387-
const meta_win = this._window_preview._windowActor.meta_window
444+
const meta_win = this._window_preview._windowActor.get_meta_window ()
445+
if (!meta_win) {
446+
return
447+
}
388448

389449
// As we known, preview shown in overview has been scaled
390450
// in overview

src/manager/rounded_corners_manager.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ export class RoundedCornersManager {
206206
return this.rounded_windows?.keys ()
207207
}
208208

209+
/** Query rounded corners effect of window actor */
210+
get_rounded_corners_effect (
211+
actor: WindowActor
212+
): RoundedCornersEffectType | null | undefined {
213+
const name = constants.ROUNDED_CORNERS_EFFECT
214+
type Res = RoundedCornersEffectType | null | undefined
215+
return this._get_actor_to_rounded (actor)?.get_effect (name) as Res
216+
}
217+
209218
// ------------------------------------------------------- [private methods]
210219

211220
/** Compute outer bound of rounded corners for window actor */
@@ -617,20 +626,11 @@ export class RoundedCornersManager {
617626
return type == WindowClientType.X11 ? actor.get_first_child () : actor
618627
}
619628

620-
/** Query rounded corners effect of window actor */
621-
private _get_rounded_corners (
622-
actor: WindowActor
623-
): RoundedCornersEffectType | null | undefined {
624-
const name = constants.ROUNDED_CORNERS_EFFECT
625-
type Res = RoundedCornersEffectType | null | undefined
626-
return this._get_actor_to_rounded (actor)?.get_effect (name) as Res
627-
}
628-
629629
/** Traversal all windows, add or remove rounded corners for them */
630630
private _update_all_window_effect_state () {
631631
global.get_window_actors ().forEach ((actor) => {
632632
const [should_have_effect] = this.should_enable_effect (actor.meta_window)
633-
const has_effect = this._get_rounded_corners (actor) != null
633+
const has_effect = this.get_rounded_corners_effect (actor) != null
634634

635635
if (should_have_effect && !has_effect) {
636636
this._add_effect (actor)
@@ -735,7 +735,7 @@ export class RoundedCornersManager {
735735
const cfg = this._get_rounded_corners_cfg (win)
736736

737737
// Skip rounded corners when window is fullscreen & maximize
738-
let effect = this._get_rounded_corners (actor)
738+
let effect = this.get_rounded_corners_effect (actor)
739739
const should_rounded = UI.ShouldHasRoundedCorners (win, cfg)
740740

741741
if (!should_rounded && effect) {

src/utils/ui.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Settings } from '@gi/Gio'
44

55
// gnome modules
66
import { openPrefs } from '@imports/misc/extensionUtils'
7+
import { PACKAGE_VERSION } from '@imports/misc/config'
78

89
// local modules
910
import { load } from '@me/utils/io'
@@ -178,3 +179,10 @@ export function ShouldHasRoundedCorners (
178179

179180
return should_has_rounded_corners
180181
}
182+
183+
/**
184+
* @returns Current version of gnome shell
185+
*/
186+
export function shell_version (): number {
187+
return Number.parseFloat (PACKAGE_VERSION)
188+
}

0 commit comments

Comments
 (0)