Skip to content

Commit

Permalink
Fix sockets on hyprland (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski authored Apr 29, 2024
1 parent 33bcaf3 commit 2be95ed
Showing 1 changed file with 15 additions and 9 deletions.
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

0 comments on commit 2be95ed

Please sign in to comment.