Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store i3 status of workspaces #89

Closed
conrad784 opened this issue Jun 7, 2018 · 6 comments
Closed

Store i3 status of workspaces #89

conrad784 opened this issue Jun 7, 2018 · 6 comments

Comments

@conrad784
Copy link

conrad784 commented Jun 7, 2018

I want to store my current workspace configuration.
Therefore I want to use pickle:

import i3ipc
import pickle
i3 = i3ipc.Connection()
pickle.dumps(i3.get_workspaces()

this will result in an error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/i3ipc/i3ipc.py", line 37, in __getattr__
    return self[name]
KeyError: '__getstate__'

This is happening in python{2,3}.
Used version of i3ipc-python: 1.5.1

@acrisci
Copy link
Member

acrisci commented Jul 17, 2018

It should raise AttributeError instead of KeyError.

@acrisci
Copy link
Member

acrisci commented Jul 17, 2018

Let me know if that fixes it.

@conrad784
Copy link
Author

yes that fixed it, thank you!

acrisci added a commit that referenced this issue Sep 25, 2018
Version 1.6.0 adds the following bugfixes and features:

* Properly tear down subscription socket (#83)
* Implement send_tick message and tick event
* Add a timeout parameter to the main function
* Implement GET_BINDING_MODES
* Implement GET_CONFIG
* Implement GET_MARKS
* Fix pickling of types by fixing a _ReplyType exception (#89)
* Add the sticky property
@Nebucatnetzer
Copy link

@conrad784 Do you have that script somewhere public? I'm trying to write a script which restores the workspaces after I've docked the notebook so that they are back on the corresponding monitor.
I reckon your script could provide some inspiration for me :)

conrad784 added a commit to conrad784/i3scripts that referenced this issue Oct 27, 2018
attention, only working with versions > 1.5.1
altdesktop/i3ipc-python#89
@conrad784
Copy link
Author

conrad784 commented Oct 27, 2018

@Nebucatnetzer uploaded my repo https://github.com/conrad784/i3scripts/blob/master/i3plug.py

if you succeed in automatically doing that when plugging to docking station I would be interested, put some time in this with my Thinkpad, but I found it still easier to just call my changing resolution manually

@Nebucatnetzer
Copy link

I don't have my notebook with the docking station yet (it will take another month...)
so I can't really test it yet.
However I'm cleaning up various scripts and do some research to be prepared :).

So far I found this two articles quite interesting.

This one has a script which is very similar to yours:
http://sergeiturukin.com/2017/07/03/laptop-dock-archlinux.html
And this one shows how to use udev to make hotpluging work:
https://frdmtoplay.com/i3-udev-xrandr-hotplugging-output-switching/
Unfortunately I wasn't able to get it working with my current laptop with just the HDMI cable.
It doesn't detect any events and the HDMI gets shown as disconnected despite being connected and the monitor showing the picture.
I hope I remember to post here in a month once I get the dock to do the real tests.

Just found this which looks as well interesting:
https://github.com/phillipberndt/autorandr

This is my current script.

import sys
import pickle
import i3ipc
import os


i3 = i3ipc.Connection()

path = "/home/andreas/.i3/workspace_mapping"

if not os.path.isfile(path):
    pickle.dump(i3.get_workspaces(), open(path, "wb"))
    os.system("xrandr --output eDP-1-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal --output HDMI-1-1 --off --output HDMI-0 --off")
    os.system("i3-msg restart")
else:
    workspace_mapping = pickle.load(open(path, "rb"))
    os.system("xrandr --output eDP-1-1 --primary --mode 1920x1080 --pos 1920x0 --rotate normal --output HDMI-1-1 --off --output HDMI-0 --mode 1920x1080 --pos 0x0 --rotate normal")
    for workspace in workspace_mapping:
        i3.command('workspace %s' % workspace['name'])
        i3.command('move workspace to output %s' % workspace['output'])
    for workspace in filter(lambda w: w['visible'], workspace_mapping):
        i3.command('workspace %s' % workspace['name'])
    os.system("i3-msg restart")
    os.remove(path)

It's much less elegant than yours however my idea is to start it by typing "docking" in Rofi and it should do the appropriate action. I know it doesn't have exception handing but for the moment it should be fine.

I like your config with the keyboard shortcuts. I got the idea from that it would be nice to have something like in Windows where you can press "Meta+p" to cycle trough the various display options.
Maybe something I'll build into my script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants