i3-ipc
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:[unmaintained] inter-process communication with i3, the improved tiling window manager.
i3-ipc
======

---

# WARNING

This code is old, largely untested and might not even support all features provided by the IPC protocol. I don't have the time to develop this further.

But there is another project that provides a great abstraction of all the IPC stuff: [i3ipc-glib](https://github.com/acrisci/i3ipc-glib).

It's possible to use this library in ruby using [gir_ffi](http://rubygems.org/gems/gir_ffi) and the following code:

```ruby
require 'gir_ffi'

namespace = 'i3ipc'
GirFFI.setup namespace

i3 = I3ipc::Connection.new(nil)

i3.command 'focus left'
```

---

inter-process communication with [i3][], the improved tiling window manager.

Installation
------------

RubyGem:

    gem install i3-ipc

Old school (for the cli script only):

    curl -s http://github.com/badboy/i3-ipc/raw/master/i3-ipc > i3-ipc &&
    chmod 755 i3-ipc &&
    mv i3-ipc /usr/local/bin/i3-ipc

If you're on [Arch Linux][arch], you can use the AUR package:

    curl http://aur.archlinux.org/packages/i3-ipc/i3-ipc/PKGBUILD &&
    makepkg -i

Use
---

    i3-ipc -t 1
    i3-ipc -t 1 -p
    i3-ipc -t 3 -j
    i3-ipc "exec xterm"

Read the [man-page][man] for more information.

Subscribing
-----------

As of commit [3db4890][] i3 added events.
For now there's only two events: `workspace` and `focus`.

According to the documentation:
> workspace
>   Sent when the user switches to a different workspace, when a new workspace is initialized or when a workspace is removed (because the last client vanished).
> output
>   Sent when RandR issues a change notification (of either screens, outputs, CRTCs or output properties).


i3-ipc uses [EventMachine][em] to receive and handle these events.

With `i3-ipc`'s interface and EventMachine as its backend it's rather easy to subscribe to this event notifying:

    I3::IPC.subscribe [:workspace] do |em, type, data|
      # ...
    end

There are 3 arguments passed to the block:

* `em` is the instance of the EM::Connection class.
To send data to the socket, you need to use `em.send_data`.
* `type` is the received message type.
This could be one of
  * MESSAGE\_TYPE\_COMMAND
  * MESSAGE\_TYPE\_GET\_WORKSPACES
  * MESSAGE\_TYPE\_SUBSCRIBE
  * MESSAGE\_TYPE\_GET\_OUTPUTS
  * EVENT\_WORKSPACE
* `data` is the received data, already parsed.

For example you can use the following code to get the actual focused screen:

    I3::IPC.subscribe [:workspace] do |em, type, data|
      case type
      when I3::IPC.message_type_get_workspaces
        data.each do |e|
          if e["focused"]
            puts "focused: %s" % e["name"]
          else
            puts "unfocused: %s" % e["name"]
          end
        end
      when I3::IPC::EVENT_WORKSPACE
        em.send_data I3::IPC.format(I3::IPC.message_type_get_workspaces)
      end
    end

A full example of how this can be used for the workspace bar can be found in the [examples][] directory.

You can use `EM.stop` to stop the connection.


What needs to be done?
----------------------

* cleanup the subscribtion frontend
* write tests
* …

Contributing
------------

Once you've made your great commits:

1. [Fork][] the project.
2. Create a topic branch - `git checkout -b my_branch`
3. Push to your branch - `git push origin my_branch`
4. Create an [Issue][] with a link to your branch
5. That's it!

Copyright
---------

Copyright (c) 2010 Jan-Erik Rediger. See LICENSE for details.

[i3]: http://i3.zekjur.net/
[arch]: http://www.archlinux.org/
[man]: http://badboy.github.com/i3-ipc/
[3db4890]: http://code.stapelberg.de/git/i3/commit/?h=next&id=3db4890683e87
[em]: http://github.com/eventmachine/eventmachine
[examples]: http://github.com/badboy/i3-ipc/tree/master/examples/
[fork]: http://help.github.com/forking/
[issue]: http://github.com/badboy/i3-ipc/issues

本源码包内暂不包含可直接显示的源代码文件,请下载源码包。