summaryrefslogtreecommitdiff
path: root/perl5/Local/Desktop/WMIPC.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl5/Local/Desktop/WMIPC.pm')
-rw-r--r--perl5/Local/Desktop/WMIPC.pm61
1 files changed, 0 insertions, 61 deletions
diff --git a/perl5/Local/Desktop/WMIPC.pm b/perl5/Local/Desktop/WMIPC.pm
deleted file mode 100644
index effa7797..00000000
--- a/perl5/Local/Desktop/WMIPC.pm
+++ /dev/null
@@ -1,61 +0,0 @@
-package Local::Desktop::WMIPC;
-use 5.036;
-
-# Copyright (C) 2024 Sean Whitton
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or (at
-# your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-use IO::Socket::UNIX;
-use parent "IO::Socket::UNIX";
-use Exporter "import";
-use overload "<>" => sub { shift->recv };
-use JSON;
-use Encode "encode";
-
-our @EXPORT_OK = ();
-
-sub new ($class, $socket = $ENV{SWAYSOCK} || $ENV{I3SOCK}) {
- bless IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => $socket)
- => $class;
-}
-
-sub send ($self, $type, $payload = "") {
- $payload = encode "UTF-8", $payload;
- my $head = pack "A6ll", "i3-ipc", length $payload, $type;
- $self->SUPER::send($head.$payload);
- return $self->recv;
-}
-
-sub recv ($self) {
- my $buf;
- $self->SUPER::recv($buf, 14);
- length $buf or die "WMIPC socket EOF";
- my $len = (unpack "A6ll", $buf)[1];
- $self->SUPER::recv($buf, $len);
- return decode_json $buf;
-}
-
-sub subscribe ($self, @event_types) {
- my $reply = $self->send(2, encode_json \@event_types);
- $reply->{success} or die "WMIPC subscription failed";
-}
-
-sub cmd ($self, @cmds) { $self->send(0, join "; ", @cmds) }
-
-sub get_tree { shift->send(4) }
-sub get_workspaces { shift->send(1) }
-
-sub send_tick ($self, $payload = "") { $self->send(10, $payload) }
-
-1;