Giter Site home page Giter Site logo

i3ipc-glib's Introduction

i3ipc-GLib

A C interface library to i3wm.

About

i3's interprocess communication (or ipc) is the interface i3wm uses to receive commands from client applications such as i3-msg. It also features a publish/subscribe mechanism for notifying interested parties of window manager events.

i3ipc-GLib is a C library for controlling the window manager. This project is intended to be useful in applications such as status line generators, pagers, notification daemons, scripting wrappers, external controllers, dock windows, compositors, config templaters, and for debugging or testing the window manager itself.

The latest documentation can be found online here.

Chat

Projects using i3ipc-GLib

Installation

Check the releases page or your package manager for a package for your distro. Additional packages are available upon request.

Building the library requires autotools. Install the project with:

./autogen.sh # --prefix=/usr might be required
make
sudo make install

The following packages are required for building i3-ipc:

  • libxcb and xcb-proto
  • glib >= 2.32
  • gobject-introspection (optional for bindings)
  • json-glib >= 0.14
  • gtk-doc-tools

Example

The i3ipc connection class extends from GObject.

#include <glib/gprintf.h>
#include <i3ipc-glib/i3ipc-glib.h>

gint main() {
  i3ipcConnection *conn;
  gchar *reply;

  conn = i3ipc_connection_new(NULL, NULL);

  reply = i3ipc_connection_message(conn, I3IPC_MESSAGE_TYPE_COMMAND, "focus left", NULL);

  g_printf("Reply: %s\n", reply);

  g_free(reply);
  g_object_unref(conn);

  return 0;
}

Compile with gcc -o example example.c $(pkg-config --libs --cflags i3ipc-glib-1.0).

Contributing

Patches are welcome by pull request to fix bugs and add features.

Task List

Here is a list of tasks that could be done.

  • Async commands

License

This work is available under the GNU General Public License (See COPYING).

Copyright © 2014, Tony Crisci

All rights reserved.

i3ipc-glib's People

Contributors

acrisci avatar ckardaris avatar cornerman avatar derpycrabs avatar fepitre avatar foggalong avatar kgilmer avatar orestisfl avatar zambito1 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

i3ipc-glib's Issues

Crash on i3 restart

While investigating this issue I consistently met crashes inside i3ipc-glib when restarting i3. Since I wasn't entirely confident that the bug was not in my code I created a minimal program to reproduce the issue (see reproduce.txt) and on my box this crashes approximately 1 out of 5 times upon restarting i3.
This is the stack trace on my box:

#0  0x00007ffff4f2b5a0 in xcb_setup_vendor_end () from /usr/lib/libxcb.so.1
#1  0x00007ffff4f2b5f9 in xcb_setup_pixmap_formats_iterator () from /usr/lib/libxcb.so.1
#2  0x00007ffff4f2b639 in xcb_setup_roots_iterator () from /usr/lib/libxcb.so.1
#3  0x00007ffff7bd2984 in i3ipc_connection_get_socket_path (err=0x7fffffffdcd8, self=0x6025c0) at i3ipc-connection.c:375
#4  i3ipc_connection_initable_init (initable=<optimized out>, cancellable=<optimized out>, err=0x602598) at i3ipc-connection.c:668
#5  0x00007ffff7bd2e9e in i3ipc_connected_constructed (gobject=0x6025c0) at i3ipc-connection.c:151
#6  0x00007ffff798d897 in ?? () from /usr/lib/libgobject-2.0.so.0
#7  0x00007ffff798f1b5 in g_object_new_valist () from /usr/lib/libgobject-2.0.so.0
#8  0x00007ffff60c081e in g_initable_new_valist () from /usr/lib/libgio-2.0.so.0
#9  0x00007ffff60c08e6 in g_initable_new () from /usr/lib/libgio-2.0.so.0
#10 0x00007ffff7bd3198 in i3ipc_connection_new (socket_path=0x0, err=0x7fffffffe150) at i3ipc-connection.c:346
#11 0x000000000040092b in construct (err=0x7fffffffe180) at reproduce.c:10
#12 0x00000000004009ae in on_shutdown (connection=0x602340, data=0x0) at reproduce.c:33
#13 0x00007ffff79881d4 in ?? () from /usr/lib/libgobject-2.0.so.0
#14 0x00007ffff79a29d6 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#15 0x00007ffff79a30bf in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#16 0x00007ffff7bd4b64 in ipc_on_data (channel=<optimized out>, condition=G_IO_IN, conn=0x602340) at i3ipc-connection.c:535
#17 0x00007ffff76b1dba in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#18 0x00007ffff76b2160 in ?? () from /usr/lib/libglib-2.0.so.0
#19 0x00007ffff76b2482 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#20 0x00007ffff71554e7 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#21 0x0000000000400a31 in main () at reproduce.c:47

My plugin always crashes at i3ipc-connection.c:539 also, although the stack below is different.
Anyone else had this issue?

Docs building

Are you sure everyone needs to build documentation for this lib? Maybe it would be better to add some configuration option to choose whether to build docs?

Documentation is offline

The link to the documentation is not valid anymore. Can you please bring back the documentation? :)

Getting marks of a container

i3 switched the mark property to marks which can contain an array of marks. We just support the old API of having one string as a mark per window.

compiled example will not run

Hi. I installed the library and compiled the example. When the resulting executable is run, it yields the message:

error while loading shared libraries: libi3ipc-glib-1.0.so.0: cannot open shared object file: No such file or directory

I tried finding the file but it's nowhere on the filesystem. Does it have to be created or did I miss some step in the installation? This is my first attempt at writing c code for linux and that could very well play its part too.

I followed the instructions for installing and tried both the latest version "0.6" and the current master branch.

Does this not work on Ubuntu 18?

Pretty much title. I was trying to install i3 gaps on ubuntu and when running sudo add-apt-repository ppa:aacebedo/libi3ipc-glib I get a 404 error.

Error while running autogen.sh

I followed the instructions in the README to build the package. While running ./autogen.sh, I encountered this error:
image
I'm not familiar with the build tools, but it seems that the ./build/autotools directory was removed in the latest commit. Could that be the reason?

Add a test suite

Use the i3ipc-python test suite as a template project.

Write tests using the python bindings. Tests should include new functionality.

Order of i3ipc_connection_get_workspaces replies

Just found this discrepency between the i3-msg cli and i3ipc-glib and was curious why. The sort order of the workspace replies is reversed in the latter.

I guess we are prepending to the reply list here because of performance consideration. Should we maybe reverse the list afterwards to keep the correct order of replies? Maybe we do this in other places as well?

How to register `user_function` to signal?

I want to know how do I exactly map my function (user_function in the documentation) to signal. Does this action assume a user has knowledge of glib itself? Provided the following code:

#define THIS_SOCKET_PATH "/run/user/1000/i3/ipc-socket.1438"

void print_change( i3ipcConnection *self, i3ipcWindowEvent *e, gpointer user_data )
{
    printf( "Change : %s\n", e->change );
}

int main()
{
    i3ipcConnection *conn;
   
    conn = i3ipc_connection_new(THIS_SOCKET_PATH, NULL);
    //subscribe to window event
    i3ipcCommandReply *cr = i3ipc_connection_subscribe( conn, I3IPC_EVENT_WINDOW, NULL );
    //check the reply
    g_printf( "Subscription:%d\n", cr->success );

    //How do I register my function `print_change? The below won't compile obviously
    //i3ipc_connection_on( conn, "window", &print_change, NULL );
    //wait for events
    i3ipc_connection_main( conn );

    g_object_unref(conn);

    return 0;
}

How do I register print_change in order it is called whenever a window event happens?

i3ipc_connection_main_with_context

I think it would be nice to have void i3ipc_connection_main_with_context(i3ipcConnection *self, GMainContext *context) in this lib. I have 2 GMainLoop's in my program and need to patch this lib to give g_main_loop_new my context. It will not break compatibility.

compiling error

i3ipc-glib/Makefile.am:71: error: HAVE_INTROSPECTION does not appear in AM_CONDITIONAL
on

jordan@jordan-ThinkPad-T480 
--------------------------- 
OS: Ubuntu 20.04 LTS x86_64 
Host: 20L5CTO1WW ThinkPad T480 
Kernel: 5.4.0-40-generic 
Uptime: 3 days, 6 hours, 27 mins 
Packages: 2108 (dpkg), 20 (snap) 
Shell: bash 5.0.16 
Resolution: 5120x1440 
DE: Regolith 
WM: i3 
Theme: Solarized-Dark-Orange [GTK3] 
Icons: DMZ-Black [GTK3] 
Terminal: x-terminal-emul 
CPU: Intel i7-8650U (8) @ 4.200GHz 
GPU: Intel UHD Graphics 620 
GPU: NVIDIA GeForce MX150 
Memory: 4012MiB / 31863MiB 

with commit

85bb2ede6d3be5f2e644324defe94d5ddda67f7a

full error

autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I build/autotools
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy --force
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build'.
libtoolize: copying file 'build/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'build/autotools'.
libtoolize: copying file 'build/autotools/libtool.m4'
libtoolize: copying file 'build/autotools/ltoptions.m4'
libtoolize: copying file 'build/autotools/ltsugar.m4'
libtoolize: copying file 'build/autotools/ltversion.m4'
libtoolize: copying file 'build/autotools/lt~obsolete.m4'
autoreconf: running: /usr/bin/autoconf --force
autoreconf: running: /usr/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:17: installing 'build/compile'
configure.ac:38: installing 'build/missing'
i3ipc-glib/Makefile.am:71: error: HAVE_INTROSPECTION does not appear in AM_CONDITIONAL
i3ipc-glib/Makefile.am: installing 'build/depcomp'
autoreconf: automake failed with exit status: 1

I would be happy to help anyway I can...

New release

Hey there,

since the last release was almost a year ago,
and I see commits like a mem leak related one,
please do a new release - better for packaging.

Truncating i3 ids

As @cornerman discovered today after I reported cornerman/i3-easyfocus#6 to his repo, i3ipc-glib truncates windows ids to gint even though they are apparently unsigned long or uint_ptr.

A quick proof of concept is available here.

$ uname -a
Linux bendem-fedora-acer 4.4.6-300.fc23.x86_64 #1 SMP Wed Mar 16 22:10:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Error running autogen.sh

When running the autogen.sh shell script I get this error:

i3ipc-glib/Makefile.am:71: error: HAVE_INTROSPECTION does not appear in AM_CONDITIONAL i3ipc-glib/Makefile.am: installing 'build/depcomp' autoreconf: automake failed with exit status: 1

Don't know what it is and/or if it is a common problem

The default example is not compiling, (i3ipc-glib is not in pkg-config)...

The README.md recommends that I compile with gcc $(pkg-config --libs --cflags i3ipc-glib-1.0) <file.c> -o <binary>, but i3ipc-glib is not in pkg-config

$ pkg-config --libs --cflags i3ipc-glib-1.0
Package i3ipc-glib-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `i3ipc-glib-1.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'i3ipc-glib-1.0', required by 'virtual:world', not found

What i need to do?

"empty" event: any way to know which workspace is emptied?

Currently there is no information about which workspace is emptied. Is there any way to know?

Use the old focused workspace isn't reliable, as windows in other workspaces can also be killed to empty another workspace without switching to it at all.

autogen finding library issue

I am running Ubuntu and when I run ./autogen.sh I get the following.

checking for json... no
configure: error: Package requirements (json-glib-1.0) were not met:

No package 'json-glib-1.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables json_CFLAGS
and json_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

I have tried a few things but I don't really know what exactly I am supposed to do to fix the issue/can't find any good resources.

when I run
locate json-glib | grep -v snap
I get

/usr/lib/x86_64-linux-gnu/libjson-glib-1.0.so.0
/usr/lib/x86_64-linux-gnu/libjson-glib-1.0.so.0.400.4
/usr/share/doc/libjson-glib-1.0-0
/usr/share/doc/libjson-glib-1.0-common
/usr/share/doc/libjson-glib-1.0-0/NEWS.gz
/usr/share/doc/libjson-glib-1.0-0/changelog.Debian.gz
/usr/share/doc/libjson-glib-1.0-0/copyright
/usr/share/doc/libjson-glib-1.0-common/changelog.Debian.gz
/usr/share/doc/libjson-glib-1.0-common/copyright
/usr/share/locale-langpack/en_AU/LC_MESSAGES/json-glib-1.0.mo
/usr/share/locale-langpack/en_GB/LC_MESSAGES/json-glib-1.0.mo
/var/lib/dpkg/info/libjson-glib-1.0-0:amd64.list
/var/lib/dpkg/info/libjson-glib-1.0-0:amd64.md5sums
/var/lib/dpkg/info/libjson-glib-1.0-0:amd64.shlibs
/var/lib/dpkg/info/libjson-glib-1.0-0:amd64.symbols
/var/lib/dpkg/info/libjson-glib-1.0-0:amd64.triggers
/var/lib/dpkg/info/libjson-glib-1.0-common.list
/var/lib/dpkg/info/libjson-glib-1.0-common.md5sums

So I thought that maybe changing line 22 in configure.ac to PKG_CHECK_MODULES([json], [libjson-glib-1.0]) in order reflect my distros name of json-glib might help. I also tried running ./configure LDFLAGS='-L/usr/lib/x86_64-linux-gnu/ -Wl,-rpath,/usr/lib/x86_64-linux-gnu/' with and without the change to line 22 based an email chain that I found. None of it works.

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.