GithubHelp home page GithubHelp logo

i3ipc's Introduction

i3ipc

Overview

i3ipc is a library for convenient access to the IPC API of the i3 window manager.

Capabilities

As of the time of writing, this library is able to access all functionality of the IPC API of i3. This includes sending commands and other message types, as well as handling subscriptions.

If you just want a quick overview of the documentation, head to go.pkgdoc.org.

Usage

Thanks to Go's built-in git support, you can start using i3ipc with a simple

import "github.com/proxypoke/i3ipc"

For everything except subscriptions, you will want to create an IPCSocket over which the communication will take place. This object has methods for all message types that i3 will accept, though some might be split into multiple methods (eg. Get_Bar_Config). You can create such a socket quite easily:

ipcsocket, err := i3ipc.GetIPCSocket()

As a simple example of what you could do next, let's get the version of i3 over our new socket:

version, err := ipcsocket.GetVersion()

For further commands, refer to go doc or use the aforementioned website.

Subscriptions

i3ipc handles subscriptions in a convenient way: you don't have to think about managing the socket or watch out for unordered replies. The appropriate method simply returns a channel from which you can read Event objects.

Here's a simple example - we subscribe to workspace events, then simple print all of them as we receive them:

ws_events, err := i3ipc.Subscribe(i3ipc.I3WorkspaceEvent)
for {
    event := <-ws_events
    fmt.Printf("Received an event: %v\n", event)
}

i3ipc currently has no way of subscribing to multiple event types over a single channel. If you want this, you can simply create multiple subscribtions, then demultiplex those channels yourself - select is your friend.

License

This program is free software under the terms of the Do What The Fuck You Want To Public License. It comes without any warranty, to the extent permitted by applicable law. For a copy of the license, see COPYING or head to http://sam.zoy.org/wtfpl/COPYING.

i3ipc's People

Contributors

avinash-bhat avatar proxypoke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

i3ipc's Issues

Selecting the current workspace blows up

I am currently on the current workspace, identified by the number 1, I am using the following script

package main

import "github.com/proxypoke/i3ipc"

func main() {
        i3ipc, err := i3ipc.GetIPCSocket()

        if err != nil {
                panic(err)
        }

        i3ipc.Command("workspace 1")
}

When I run it (to selected the currently selected workspace), it crashes with the following error:

$ go run i3_ipc.go
panic: runtime error: index out of range

goroutine 1 [running]:
runtime.panic(0x5296c0, 0x6b96b7)
    /usr/lib/google-golang/src/pkg/runtime/panic.c:266 +0xb6
github.com/proxypoke/i3ipc.(*IPCSocket).Command(0x4c210066f90, 0x560d90, 0xb, 0x4f0900, 0x0, ...)
    /usr/local/google/home/wmn/code/go/src/github.com/proxypoke/i3ipc/command.go:43 +0x1f4
main.main()
    /tmp/i3_ipc.go:12 +0x81

goroutine 4 [IO wait]:
net.runtime_pollWait(0x7f4002b8e248, 0x72, 0x0)
    /usr/lib/google-golang/src/pkg/runtime/netpoll.goc:116 +0x6a
net.(*pollDesc).Wait(0x4c2100501b0, 0x72, 0x7f4002b8d0c0, 0xb)
    /usr/lib/google-golang/src/pkg/net/fd_poll_runtime.go:81 +0x34
net.(*pollDesc).WaitRead(0x4c2100501b0, 0xb, 0x7f4002b8d0c0)
    /usr/lib/google-golang/src/pkg/net/fd_poll_runtime.go:86 +0x30
net.(*netFD).Read(0x4c210050150, 0x4c21000a7c0, 0xe, 0xe, 0x0, ...)
    /usr/lib/google-golang/src/pkg/net/fd_unix.go:204 +0x2a0
net.(*conn).Read(0x4c210000100, 0x4c21000a7c0, 0xe, 0xe, 0xe, ...)
    /usr/lib/google-golang/src/pkg/net/net.go:122 +0xc5
github.com/proxypoke/i3ipc.(*IPCSocket).recv(0x4c210020360, 0x0, 0x0, 0x0, 0x0, ...)
    /usr/local/google/home/wmn/code/go/src/github.com/proxypoke/i3ipc/socket.go:100 +0xc1
github.com/proxypoke/i3ipc.(*IPCSocket).listen(0x4c210020360)
    /usr/local/google/home/wmn/code/go/src/github.com/proxypoke/i3ipc/subscribe.go:107 +0x41
created by github.com/proxypoke/i3ipc.init·1
    /usr/local/google/home/wmn/code/go/src/github.com/proxypoke/i3ipc/subscribe.go:155 +0x2c3

goroutine 6 [IO wait]:
net.runtime_pollWait(0x7f4002b8e1a0, 0x72, 0x0)
    /usr/lib/google-golang/src/pkg/runtime/netpoll.goc:116 +0x6a
net.(*pollDesc).Wait(0x4c210050450, 0x72, 0x7f4002b8d0c0, 0xb)
    /usr/lib/google-golang/src/pkg/net/fd_poll_runtime.go:81 +0x34
net.(*pollDesc).WaitRead(0x4c210050450, 0xb, 0x7f4002b8d0c0)
    /usr/lib/google-golang/src/pkg/net/fd_poll_runtime.go:86 +0x30
net.(*netFD).Read(0x4c2100503f0, 0x4c21000a8b0, 0xe, 0xe, 0x0, ...)
    /usr/lib/google-golang/src/pkg/net/fd_unix.go:204 +0x2a0
net.(*conn).Read(0x4c2100001f8, 0x4c21000a8b0, 0xe, 0xe, 0xe, ...)
    /usr/lib/google-golang/src/pkg/net/net.go:122 +0xc5
github.com/proxypoke/i3ipc.(*IPCSocket).recv(0x4c210020d80, 0x0, 0x0, 0x0, 0x0, ...)
    /usr/local/google/home/wmn/code/go/src/github.com/proxypoke/i3ipc/socket.go:100 +0xc1
github.com/proxypoke/i3ipc.(*IPCSocket).listen(0x4c210020d80)
    /usr/local/google/home/wmn/code/go/src/github.com/proxypoke/i3ipc/subscribe.go:107 +0x41
created by github.com/proxypoke/i3ipc.init·1
    /usr/local/google/home/wmn/code/go/src/github.com/proxypoke/i3ipc/subscribe.go:155 +0x2c3

goroutine 7 [finalizer wait]:
runtime.park(0x40a350, 0x6bc6d0, 0x6bad88)
    /usr/lib/google-golang/src/pkg/runtime/proc.c:1342 +0x66
runfinq()
    /usr/lib/google-golang/src/pkg/runtime/mgc0.c:2312 +0x84
runtime.goexit()
    /usr/lib/google-golang/src/pkg/runtime/proc.c:1394

goroutine 9 [IO wait]:
net.runtime_pollWait(0x7f4002b8e0f8, 0x72, 0x0)
    /usr/lib/google-golang/src/pkg/runtime/netpoll.goc:116 +0x6a
net.(*pollDesc).Wait(0x4c2100507d0, 0x72, 0x7f4002b8d0c0, 0xb)
    /usr/lib/google-golang/src/pkg/net/fd_poll_runtime.go:81 +0x34
net.(*pollDesc).WaitRead(0x4c2100507d0, 0xb, 0x7f4002b8d0c0)
    /usr/lib/google-golang/src/pkg/net/fd_poll_runtime.go:86 +0x30
net.(*netFD).Read(0x4c210050770, 0x4c21000ad20, 0xe, 0xe, 0x0, ...)
    /usr/lib/google-golang/src/pkg/net/fd_unix.go:204 +0x2a0
net.(*conn).Read(0x4c2100002d8, 0x4c21000ad20, 0xe, 0xe, 0xe, ...)
    /usr/lib/google-golang/src/pkg/net/net.go:122 +0xc5
github.com/proxypoke/i3ipc.(*IPCSocket).recv(0x4c210066690, 0x0, 0x0, 0x0, 0x0, ...)
    /usr/local/google/home/wmn/code/go/src/github.com/proxypoke/i3ipc/socket.go:100 +0xc1
github.com/proxypoke/i3ipc.(*IPCSocket).listen(0x4c210066690)
    /usr/local/google/home/wmn/code/go/src/github.com/proxypoke/i3ipc/subscribe.go:107 +0x41
created by github.com/proxypoke/i3ipc.init·1
    /usr/local/google/home/wmn/code/go/src/github.com/proxypoke/i3ipc/subscribe.go:155 +0x2c3
exit status 2

panic while using non X11 tty

I am receiving the following error while using a go project over a non X11 tty.

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x58 pc=0x43a26a]

goroutine 1 [running]:
runtime.panic(0x529780, 0x6b94a8)
    /usr/local/go/src/pkg/runtime/panic.c:266 +0xb6
github.com/proxypoke/i3ipc.(*IPCSocket).Raw(0xc21001d360, 0x2, 0xc21000a430, 0xd, 0x0, ...)
    $GOPATH/src/github.com/proxypoke/i3ipc/socket.go:171 +0x4ba
github.com/proxypoke/i3ipc.(*IPCSocket).subscribe(0xc21001d360, 0x7fe600000000, 0x0, 0x0)
    $GOPATH/src/github.com/proxypoke/i3ipc/subscribe.go:69 +0xc9
github.com/proxypoke/i3ipc.init·1()
    $GOPATH/src/github.com/proxypoke/i3ipc/subscribe.go:148 +0x11f
github.com/proxypoke/i3ipc.init()
    $GOPATH/src/github.com/proxypoke/i3ipc/workspaces.go:45 +0x60
main.init()
    $GOPATH/src/github.com/Avinash-Bhat/i3go/main.go:79 +0x47

is this a i3ipc issue or i3wm issue or a go issue like this?

the project in question is over here

init() function fails when i3 is not available

When the i3ipc library is imported, the init() function is run, regardless whether the library is used or not. This causes unwanted side-effects in environments where i3 is not available, e.g. when running integration tests on Travis:

2015/10/04 14:58:34 Can't get i3 socket. Please make sure i3 is running. exec: "i3": executable file not found in $PATH.
FATAL command "test" failed: exit status 1

There is currently no way to disable this behavior, please move the code from the init function to another function so that it is not run unless the library is used.

Transfer project?

This repo is suggested by the official i3 documentation.

However none of the pull requests got any reply even though they add missing functionality.
Do you still want to take care of this repo? If not would you agree to grant access to some other person(s)?

No offense meant, if you don't have the time or motivation to do it that is perfectly fine, however I would love to see this library evolve to make it usable to do the i3 scripting in go.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.