Re: [i3] i3bar POC: workspace button with focused window name

2013-03-21 Thread Axel Wagner
Hi,

Excerpts from Fam Zheng's message of 2013-03-21 04:16:32 +0100:
 Of course a bar option can be added too to enable/disable this
 feature. Or even give some sophisticated format option for the title,
 and also enable user to manually rename it. Would this feature be
 useful?
 
 To do this we need to add a few new events trigger and maybe a title
 field in get_workspace msg. I already have a demo modification for you
 to test how it feels, based on master. Now my life with many
 workspaces is much easier. :)

I think the only modification needed to i3 would be a focus-change-event
(and maybe with a little hack not even that) and what you want can be
entirely done with an ipc-script, no modifications to i3bar necessary.

So I would do it like that: Have a daemon running that listens for focus
events, everytime such an event is triggered, get the current
workspaces, find out for each one, what window is currently focused
(maybe the focus event could include the „change“-data which would make
this step unnecessary) and change the title of that workspace to the
title of that window.

As I said, I think it could also be possible with a little „hack“: By
using the workspace-event you could change the title everytime you
change away from a ws. Then you would have accurately titles for every
ws _not_ currently focused, which should be enough for getting an
overview.

I think i3bar is definitely the wrong place to do what you want, though
it is a good idea.
Doing it in i3 (by including an option to change the ws-title to the
currently focused window) would be better, because then the feature
would be available to users of alternative ws-bars, if they exist. But
this would still be a lot of complexity added to i3 in C for something,
that can be done with IPC and a scripting-language.
Implementing the focus-change-event you should do in any case, imho,
because I ran over a few usecases which would profit from that in my
time.


Regards,

Axel


signature.asc
Description: PGP signature


Re: [i3] i3bar POC: workspace button with focused window name

2013-03-21 Thread justus jonas

Hi,

Am 21.03.2013 13:27, schrieb Fam Zheng:

On Thu, Mar 21, 2013 at 6:31 PM, Axel Wagner m...@merovius.de wrote:

Hi,

Excerpts from Fam Zheng's message of 2013-03-21 04:16:32 +0100:

Of course a bar option can be added too to enable/disable this
feature. Or even give some sophisticated format option for the title,
and also enable user to manually rename it. Would this feature be
useful?

To do this we need to add a few new events trigger and maybe a title
field in get_workspace msg. I already have a demo modification for you
to test how it feels, based on master. Now my life with many
workspaces is much easier. :)


I think the only modification needed to i3 would be a focus-change-event
(and maybe with a little hack not even that) and what you want can be
entirely done with an ipc-script, no modifications to i3bar necessary.

So I would do it like that: Have a daemon running that listens for focus
events, everytime such an event is triggered, get the current
workspaces, find out for each one, what window is currently focused
(maybe the focus event could include the „change“-data which would make
this step unnecessary) and change the title of that workspace to the
title of that window.





As I said, I think it could also be possible with a little „hack“: By
using the workspace-event you could change the title everytime you
change away from a ws. Then you would have accurately titles for every
ws _not_ currently focused, which should be enough for getting an
overview.

I think i3bar is definitely the wrong place to do what you want, though
it is a good idea.
Doing it in i3 (by including an option to change the ws-title to the
currently focused window) would be better, because then the feature
would be available to users of alternative ws-bars, if they exist. But
this would still be a lot of complexity added to i3 in C for something,
that can be done with IPC and a scripting-language.
Implementing the focus-change-event you should do in any case, imho,
because I ran over a few usecases which would profit from that in my
time.


Event is the easiest part, just send an event at the end of `con_focus
for window, as well as handle_destroy_notify_event,
handle_windowname_change, would suffice.

Renaming would be trickier, that would need a remap of key binding
too, which sounds not so neat. IMO name of ws and caption or
title of ws should be isolated, because mixing ws identifier and
it's display is not a good idea, despite the complexity for the
ipc-script to decompose and extract the original ws name, and query
and parse the whole tree, and then remap all the keybindings to this
workspace (would be a nightmare if many bindings refer to it) for each
change.



actually, you would not need to change your keybinding. you could use 
the i3-command workspace number ws-id in your config file. Let's 
assume you have workspaces 1: www and 2: mail. Then configure your 
workspace switchting keys to the following commands:

bindsym $mod+$1 workspace number 1: www
bindsym $mod+$2 workspace number 2: mail

if you now rename the current workspace (e.g. 1: www) with rename 
workspace to '1: foo', you can still access this workspace with your 
configured keybinding.




The thing will be much easier if i3 adds a caption property to ws,
so that i3bar and other bars can optionally render it to user, and
this also benefits that renaming a workspace becomes more
straightforward (no longer messing any keybinding). Maybe I'm too used
to tmux.

This is 100 LOC for both i3 and i3bar changes, if this feature is
demanded, I can post my patch for review.




Regards,

Axel


best
johannes



Re: [i3] i3bar POC: workspace button with focused window name

2013-03-21 Thread Fam Zheng
Thanks for that! `workspace number #` is a nice syntax!

Best regards!
Fam Zheng


On Thu, Mar 21, 2013 at 8:37 PM, justus jonas hap...@web.de wrote:
 Hi,

 Am 21.03.2013 13:27, schrieb Fam Zheng:

 On Thu, Mar 21, 2013 at 6:31 PM, Axel Wagner m...@merovius.de wrote:

 Hi,

 Excerpts from Fam Zheng's message of 2013-03-21 04:16:32 +0100:

 Of course a bar option can be added too to enable/disable this
 feature. Or even give some sophisticated format option for the title,
 and also enable user to manually rename it. Would this feature be
 useful?

 To do this we need to add a few new events trigger and maybe a title
 field in get_workspace msg. I already have a demo modification for you
 to test how it feels, based on master. Now my life with many
 workspaces is much easier. :)


 I think the only modification needed to i3 would be a focus-change-event
 (and maybe with a little hack not even that) and what you want can be
 entirely done with an ipc-script, no modifications to i3bar necessary.

 So I would do it like that: Have a daemon running that listens for focus
 events, everytime such an event is triggered, get the current
 workspaces, find out for each one, what window is currently focused
 (maybe the focus event could include the „change“-data which would make
 this step unnecessary) and change the title of that workspace to the
 title of that window.




 As I said, I think it could also be possible with a little „hack“: By
 using the workspace-event you could change the title everytime you
 change away from a ws. Then you would have accurately titles for every
 ws _not_ currently focused, which should be enough for getting an
 overview.

 I think i3bar is definitely the wrong place to do what you want, though
 it is a good idea.
 Doing it in i3 (by including an option to change the ws-title to the
 currently focused window) would be better, because then the feature
 would be available to users of alternative ws-bars, if they exist. But
 this would still be a lot of complexity added to i3 in C for something,
 that can be done with IPC and a scripting-language.
 Implementing the focus-change-event you should do in any case, imho,
 because I ran over a few usecases which would profit from that in my
 time.


 Event is the easiest part, just send an event at the end of `con_focus
 for window, as well as handle_destroy_notify_event,
 handle_windowname_change, would suffice.

 Renaming would be trickier, that would need a remap of key binding
 too, which sounds not so neat. IMO name of ws and caption or
 title of ws should be isolated, because mixing ws identifier and
 it's display is not a good idea, despite the complexity for the
 ipc-script to decompose and extract the original ws name, and query
 and parse the whole tree, and then remap all the keybindings to this
 workspace (would be a nightmare if many bindings refer to it) for each
 change.


 actually, you would not need to change your keybinding. you could use the
 i3-command workspace number ws-id in your config file. Let's assume you
 have workspaces 1: www and 2: mail. Then configure your workspace
 switchting keys to the following commands:
 bindsym $mod+$1 workspace number 1: www
 bindsym $mod+$2 workspace number 2: mail

 if you now rename the current workspace (e.g. 1: www) with rename workspace
 to '1: foo', you can still access this workspace with your configured
 keybinding.



 The thing will be much easier if i3 adds a caption property to ws,
 so that i3bar and other bars can optionally render it to user, and
 this also benefits that renaming a workspace becomes more
 straightforward (no longer messing any keybinding). Maybe I'm too used
 to tmux.

 This is 100 LOC for both i3 and i3bar changes, if this feature is
 demanded, I can post my patch for review.



 Regards,

 Axel


 best
 johannes



Re: [i3] i3bar POC: workspace button with focused window name

2013-03-21 Thread Axel Wagner
Hi,

what justus said was also my first reaction. Everything you explained in
your second mail is pretty much implemented conceptually, with the
“caption” being called name and “identifier” being the number.
The complexity of the needed ipc-script is reduced accordingly, you only
need something like:
while true:
wait_for_event
workspaces = get_workspaces
for each workspace:
active_con = null
for each container:
if container.focused:
active_con = container
break
workspace.rename(%d: %s, workspace.number, active_con.title)

With one of the libraries existing that encapsulate the
i3-protocol a working script should not be very much longer than the
pseudocode above (I'm actually not sure wether the number-syntax works
in the rename command, if not, that would be a nice thing to implement
too, imho ;).

I also presume that a change as you originally proposed would not be
accepted in the mainline i3, for the reasons I mentioned, but I only
extrapolate from similar proposals in the past.

Kind regards,

Axel


signature.asc
Description: PGP signature


Re: [i3] i3bar POC: workspace button with focused window name

2013-03-21 Thread Ultrabug
Sorry, I left my debug stuff at the end of the script, here's the real 
py file.. :-/


On 21/03/2013 19:23, Ultrabug wrote:

Hi,

On 21/03/2013 14:41, Fam Zheng wrote:
OK, I get it. So the remaining is events, and possibly number syntax 
in rename.


Best regards!
Fam Zheng


On Thu, Mar 21, 2013 at 9:13 PM, Axel Wagner m...@merovius.de wrote:

Hi,

what justus said was also my first reaction. Everything you 
explained in

your second mail is pretty much implemented conceptually, with the
“caption” being called name and “identifier” being the number.
The complexity of the needed ipc-script is reduced accordingly, you 
only

need something like:
while true:
 wait_for_event
 workspaces = get_workspaces
 for each workspace:
 active_con = null
 for each container:
 if container.focused:
 active_con = container
 break
 workspace.rename(%d: %s, workspace.number, active_con.title)

With one of the libraries existing that encapsulate the
i3-protocol a working script should not be very much longer than the
pseudocode above (I'm actually not sure wether the number-syntax works
in the rename command, if not, that would be a nice thing to implement
too, imho ;).
You got my mind running on this, I thought this would be easily done 
with a custom class using py3status [1] :)
I'm glad to attach the implementation, it works great and should 
answer your initial request.


Basically, with a standard 1sec interval py3status usage, you will 
have a pretty responsive renaming going on. Few thoughts if we wanted 
to push it further :

- We could an event subscription to handle this in a thread
- We could avoid using i3-py by using the standard i3-msg so this 
wouldn't need any dependency and would work out of the box


 [1] https://github.com/ultrabug/py3status

One limitation which I didnt have the time to try to fix is that 
renaming the workspaces breaks the window assignment you may have 
configured.

I also presume that a change as you originally proposed would not be
accepted in the mainline i3, for the reasons I mentioned, but I only
extrapolate from similar proposals in the past.

Kind regards,

Axel

Hope this helps

Ultrabug


# -*- coding: utf-8 -*-

class Py3status:
	
	Inspired by Fam Zheng request on mailing list [1]
	Thanks to Axel Wagner and Justus Jonas for their interesting replies

	This class renames the current workspace with the name of the focused window
	We do a small operation on the name for convenience which you can adapt ofc

	NOTE: my workspaces are named 1 NAME with no : so you may want to change
	the NUM_SPLIT variable to your separator

	NOTE: you need i3-py [2] for this class to work

	TODO: this affects window assignment settings ;(

	[1] http://article.gmane.org/gmane.comp.window-managers.i3.general/918/
	[2] https://github.com/ziberna/i3-py | https://pypi.python.org/pypi/i3-py
	
	def rename_workspace(self, json, i3status_config):
		response = {'full_text' : '', 'name' : 'rename_workspace'}

		NUM_SPLIT =  
		LONG_NAME_SPLIT =  - 
		LONG_NAME_INDEX = -1

		try:
			import i3
			from syslog import syslog
			from syslog import LOG_INFO
			nodes = i3.filter(nodes=[], focused=True)
			for node in nodes:
# dont rename empty workspaces
if 'num' in node : continue

# NOTE: quick hack transformation for long named windows
# 'Inbox - XXX account - Mozilla Thunderbird' becomes 'Mozilla Thunderbird'
node['name'] = node['name'].split(LONG_NAME_SPLIT)[LONG_NAME_INDEX]

current_workspace = [ws for ws in i3.get_workspaces() if ws['focused']][0]
ws_num, ws_name = current_workspace['name'].split(NUM_SPLIT, 1)
new_name = %s %s % (ws_num, node['name'])
if new_name != current_workspace['name']:
	cmd = 'rename workspace %s %s to %s' % (ws_num, ws_name, new_name)
	i3.msg('command', cmd)
	syslog(LOG_INFO, cmd)
		except Exception, e:
			raise
		finally:
			# for maximum responsiveness, dont cache this class
			response.update({'cached_until': 10})
			return (0, response)