Question

So I'm making a Gnome Shell extension. And I want to be able to run some command. (The command is actually "synclient -m 100", but that is off topic)

So, what I have done so far is

s=GLib.spawn_async_with_pipes(null, ["synclient","-m","100"], null, GLib.SpawnFlags.SEARCH_PATH,null)
c=GLib.IOChannel.unix_new(s[3])

The first line spawns my process. It is definitely working.

s[3] is the file descriptor for the stout of the process. (It has something to do with pipes. Not really sure about the whole pipe thing.)

Anyway, my problem is that I can't seem to read anything from the output of synclient.

This is what I'm using for reference, but it seems that not all of the functions work. For example, I want to use add_watch, but that apperently doesn't work with gnome extensions.

I've tried using a bunch or read functions and specifically read_line_string, but they all have problems. For read_line_string it seems like it should all work except I can't figure out how to create a StringBuilder object to pass as an argument.

So, does anyone know how to get the output of a command?

Edit: also I'm kind of confused about which language the extensions use. I think it's javascript, but the docs I'm using seem to make me think Vala, whatever that is (I'm guessing a variation of java?).

Edit 2:

So, what I've got now is

let [res, pid, in_fd, out_fd, err_fd] = 
  GLib.spawn_async_with_pipes(
    null, ["synclient","-m","100"], null, GLib.SpawnFlags.SEARCH_PATH, null);
out_reader = new Gio.DataInputStream({ base_stream: new Gio.UnixInputStream({fd: out_fd}) });

And to read a line:

let [out, size] = out_reader.read_line(null);

This gives me the output of the command, but it still doesn't give me any way to get some callback whenever the DataInputStream is changed. I need to be able to do something whenever there is a new line in the stream.

Was it helpful?

Solution

Gnome Shell extensions are usually written in JavaScript. They use JavaScript bindings to libraries like GLib that are written in C. There are also Vala bindings to those libraries, and that is the documentation you are looking at. Here is the documentation for the JS bindings, unofficial as yet.

StringBuilder is a Vala language feature that corresponds to GLib.String in JS.

How do you know add_watch() doesn't work? What do you expect and what does it do instead?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top