fennerm / flashfocus

Simple focus animations for tiling window managers.
MIT License
751 stars 9 forks source link

Can't set rules: key error window_class #43

Closed indeedwatson closed 4 years ago

indeedwatson commented 4 years ago
 > ~ INFO: Detected display protocol: X11                                                            ⚙ 1
INFO: Loading configuration from /home/yama/.config/flashfocus/flashfocus.yml
INFO: Initializing with parameters:
{'ntimepoints': 10, 'default_opacity': 1.0, 'rules': [{'window_class': re.compile('Termite'), 'default_opacity': 0.8, 'flash_opacity': 0.6, 'simple': False, 'flash_on_focus': True, 'ntimepoints': 10, 'time': 600.0, 'flash_lone_windows': 'always'}], 'flash_on_focus': True, 'flash_opacity': 0.6, 'time': 600.0, 'simple': False, 'flash_fullscreen': True, 'flash_lone_windows': 'always'}
INFO: Initializing default window opacity...
INFO: Setting all windows to their default opacity...
Traceback (most recent call last):
  File "/usr/bin/flashfocus", line 12, in <module>
    sys.exit(cli())
  File "/usr/lib/python3.8/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/flashfocus/cli.py", line 87, in cli
    init_server(kwargs)
  File "/usr/lib/python3.8/site-packages/flashfocus/cli.py", line 106, in init_server
    return server.event_loop()
  File "/usr/lib/python3.8/site-packages/flashfocus/server.py", line 55, in event_loop
    self._set_all_window_opacity_to_default()
  File "/usr/lib/python3.8/site-packages/flashfocus/server.py", line 105, in _set_all_window_opacity_to_default
    self.router.route_request(WMEvent(window=window, event_type=WMEventType.WINDOW_INIT))
  File "/usr/lib/python3.8/site-packages/flashfocus/router.py", line 102, in route_request
    self._route_window_init(message.window)
  File "/usr/lib/python3.8/site-packages/flashfocus/router.py", line 117, in _route_window_init
    rule, flasher = self._match(window)
  File "/usr/lib/python3.8/site-packages/flashfocus/router.py", line 140, in _match
    if window.match(rule):
  File "/usr/lib/python3.8/site-packages/flashfocus/display_protocols/x11.py", line 113, in match
    if criteria.get(prop) and not match_regex(criteria[prop], self.properties[prop]):
KeyError: 'window_class'

Only getting this error when I uncomment:

rules:
  - window-class: Termite
  default-opacity: 0.8
fennerm commented 4 years ago

Based on that snippet I’d guess you have an indentation issue. default-opacity should have same indentation level as window-class

indeedwatson commented 4 years ago

This how it should be?

rules:
  - window-class: Termite
    default-opacity: 0.8

Cause that gives me the same error.

fennerm commented 4 years ago

Gotcha sounds like thats not it then. I’ll look into it

Artturin commented 4 years ago
rules:
   - app-id: floating-term
     flash-on-focus: False

Gives


INFO: Detected display protocol: wayland - sway
Traceback (most recent call last):
  File "/usr/bin/flashfocus", line 12, in <module>
    sys.exit(cli())
  File "/usr/lib/python3.8/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.8/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/flashfocus/cli.py", line 87, in cli
    init_server(kwargs)
  File "/usr/lib/python3.8/site-packages/flashfocus/cli.py", line 101, in init_server
    config = load_merged_config(config_file_path=Path(config_file_path), cli_options=cli_options)
  File "/usr/lib/python3.8/site-packages/flashfocus/config.py", line 324, in load_merged_config
    user_config = load_config(config_file_path)
  File "/usr/lib/python3.8/site-packages/flashfocus/config.py", line 146, in load_config
    config: Dict = yaml.load(f, Loader=yaml.FullLoader)
  File "/usr/lib/python3.8/site-packages/yaml/__init__.py", line 114, in load
    return loader.get_single_data()
  File "/usr/lib/python3.8/site-packages/yaml/constructor.py", line 41, in get_single_data
    node = self.get_single_node()
  File "/usr/lib/python3.8/site-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/usr/lib/python3.8/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/usr/lib/python3.8/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/lib/python3.8/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/usr/lib/python3.8/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/usr/lib/python3.8/site-packages/yaml/parser.py", line 438, in parse_block_mapping_key
    raise ParserError("while parsing a block mapping", self.marks[-1],```
fennerm commented 4 years ago

Ugh sorry I haven’t had time to look into this yet

fennerm commented 4 years ago

@indeedwatson @Leo-Lahti I'm not able to replicate either of these on my machine. Could you paste the output of pip freeze?

indeedwatson commented 4 years ago

@fennerm https://paste.xinu.at/rGyXo/

fennerm commented 4 years ago

@indeedwatson I still haven't been able to reproduce but I have a hunch that there is a window with weirdly defined window id/class that is throwing things off. I pushed a release (v2.1.2) which better handles windows with absent class. Let me know if this improves things.

@Leo-Lahti I think your issue is probably unrelated. Could you post the output of pip freeze and the contents of your config file?

indeedwatson commented 4 years ago

@fennerm Yup looks like that solved it. Feel free to close if you deem leo's issue to be a separate one.

Artturin commented 4 years ago

@fennerm hmmm seems like it works after i removed the space in the front of rules: and indented app-id and flash-on-focus correctly

doesnt work

 rules:
   - app-id: floating-term
     flash-on-focus: False

works

rules:
  - app-id: floating-term
    flash-on-focus: False
fennerm commented 4 years ago

Ah I see, yeah yaml is a stickler for spacing. I'll close this out. Looks like this error also wasn't being caught correctly. Fixing that in another patch release.