Skip to content

Commit

Permalink
Merge pull request #236 from gjsify/shell-fragment-type
Browse files Browse the repository at this point in the history
feat(shell): Add Cogl.SnippetHook support for Shell.GLSLEffect.add_glsl_snippet
  • Loading branch information
JumpLink authored Feb 17, 2025
2 parents 70f9c42 + 1fad3e6 commit 393b560
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/lib/src/injections/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import tracker1 from "./tracker1.js";
import gee08 from "./gee08.js";
import gee1 from "./gee1.js";
import gtk4 from "./gtk4.js";
import { shell14, shell15 } from "./shell.js";
import { IntrospectedNamespace } from "../gir/namespace.js";
import { NSRegistry } from "../gir/registry.js";

Expand Down Expand Up @@ -37,4 +38,6 @@ export function inject(registry: NSRegistry) {
$_(gee08);
$_(gee1);
$_(gtk4);
$_(shell14);
$_(shell15);
}
45 changes: 45 additions & 0 deletions packages/lib/src/injections/shell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { IntrospectedNamespace } from "../gir/namespace.js";
import { TypeIdentifier, OrType, NullableType } from "../gir.js";
import { NSRegistry } from "../gir/registry.js";

const shellTemplate = (version: string) => ({
namespace: "Shell",
version,
modifier(namespace: IntrospectedNamespace, registry: NSRegistry) {
// Get the GLSLEffect class which contains the add_glsl_snippet method
const GLSLEffect = namespace.assertClass("GLSLEffect");

// Find the add_glsl_snippet method
const addGlslSnippet = GLSLEffect.members.find(m => m.name === "add_glsl_snippet");

// Change
// ```ts
// add_glsl_snippet(hook: SnippetHook | null, declarations: string, code: string, is_replace: boolean): void;
// ```
// to
// ```ts
// add_glsl_snippet(hook: SnippetHook | Cogl.SnippetHook | null, declarations: string, code: string, is_replace: boolean): void;
// ```

if (addGlslSnippet) {
// Create a new parameter with updated type using copy()
const updatedParameter = addGlslSnippet.parameters[0].copy({
type: new NullableType(
new OrType(
new TypeIdentifier("SnippetHook", "Shell"),
new TypeIdentifier("SnippetHook", "Cogl")
)
)
});

// Replace the original parameter
addGlslSnippet.parameters[0] = updatedParameter;
}
}
});

/** Shell 14 was introduced with GNOME 45 */
export const shell14 = shellTemplate("14");

/** Shell 15 was introduced with GNOME 48 */
export const shell15 = shellTemplate("15");

0 comments on commit 393b560

Please sign in to comment.