Re: [i3] [PATCH 2/5] Added "focus" IPC message/event.

  • From: Kevin Murphy <kemurphy.cmu@xxxxxxxxx>
  • To: Michael Stapelberg <michael@xxxxxxxx>
  • Date: Tue, 20 Nov 2012 04:37:28 -0500

I figured there was a better way to do this, thanks for the suggestions :)
I submitted these more for comments than for "please merge as is" anyway,
so that's helpful. I'll play with it more when I get some spare time in a
couple weeks.

Thanks,
Kevin

On Tue, Nov 20, 2012 at 3:28 AM, Michael Stapelberg <michael@xxxxxxxx>wrote:

Hi Kevin,

Kevin Murphy <kemurphy.cmu@xxxxxxxxx> writes:
+/** Request the id and title of the focused window */
+#define I3_IPC_MESSAGE_TYPE_GET_FOCUS 8
I’d prefer this to be "GET_FOCUSED", just because getting the x11 focus
is a trivial thing to do already for which you wouldn’t need window
manager support.

+ ipc_send_event("focus", I3_IPC_EVENT_FOCUS,
"{\"change\":\"window\"}");
Is there a reason why you don’t include the properties you send in
GET_FOCUS replies right here? You could avoid one extra round-trip (and
race conditions!) with that.

+ if (con == focused)
+ ipc_send_event("focus", I3_IPC_EVENT_FOCUS,
"{\"change\":\"title\"}");
Same here.

+ y(map_open);
+
+ ystr("id");
+ if (focused->window != NULL) {
+ y(integer, focused->window->id);
+ } else {
+ y(integer, focused->frame);
+ }
+
+ ystr("title");
+ if (focused->window && focused->window->name)
+ ystr(i3string_as_utf8(focused->window->name));
+ else if (focused->type != CT_WORKSPACE && focused->name)
+ ystr(focused->name);
+ else
+ ystr("");
+
+ y(map_close);
Is there a reason to not use dump_node? Actually, is there a reason to
not use the GET_TREE ipc request and then filter for the focused node
(which is trivial)? It includes the same properties.

I think the event part of this is rather nice, but the request/reply is
unnecessary. You might want to have a look at
workspace.c:ipc_send_workspace_focus_event to see how other events
include the entire sub-tree. Using this technique would lead to a more
consistent IPC interface than your suggestion.

--
Best regards,
Michael

Other related posts: