Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sockets on hyprland #398

Merged
merged 3 commits into from
Apr 29, 2024
Merged
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
24 changes: 15 additions & 9 deletions src/service/hyprland.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import Gio from 'gi://Gio';
import Service from '../service.js';

Gio._promisify(Gio.DataInputStream.prototype, 'read_upto_async');
const HIS = GLib.getenv('HYPRLAND_INSTANCE_SIGNATURE');

const socket = (path: string) => new Gio.SocketClient()
.connect(new Gio.UnixSocketAddress({ path }), null);
const HIS = GLib.getenv('HYPRLAND_INSTANCE_SIGNATURE');
const XDG_RUNTIME_DIR = GLib.getenv('XDG_RUNTIME_DIR') || '/';

export class ActiveClient extends Service {
static {
Expand Down Expand Up @@ -136,19 +135,26 @@ export class Hyprland extends Service {
for (const c of JSON.parse(this.message('j/clients')) as Client[])
this._clients.set(c.address, c);


// this._syncWorkspaces();
// this._syncClients();

this._watchSocket(new Gio.DataInputStream({
close_base_stream: true,
base_stream: socket(`/tmp/hypr/${HIS}/.socket2.sock`)
base_stream: this._connection('socket2')
.get_input_stream(),
}));

this._active.connect('changed', () => this.changed('active'));
}

private _connection(socket: 'socket' | 'socket2') {
const sock = (pre: string) => `${pre}/hypr/${HIS}/.${socket}.sock`;

const path = GLib.file_test(sock(XDG_RUNTIME_DIR), GLib.FileTest.EXISTS)
? sock(XDG_RUNTIME_DIR)
: sock('/tmp');

return new Gio.SocketClient()
.connect(new Gio.UnixSocketAddress({ path }), null);
}

private _watchSocket(stream: Gio.DataInputStream) {
stream.read_line_async(0, null, (stream, result) => {
if (!stream)
Expand All @@ -168,7 +174,7 @@ export class Hyprland extends Service {
};

private _socketStream(cmd: string) {
const connection = socket(`/tmp/hypr/${HIS}/.socket.sock`);
const connection = this._connection('socket');

connection
.get_output_stream()
Expand Down
Loading