sunaku / wmiirc

Ruby configuration for WMII window manager
ISC License
82 stars 26 forks source link

Change display:status from Array into Hash #7

Closed nougad closed 14 years ago

nougad commented 14 years ago

Hi,

today I had some time to look at the new version. It works really well. The idea of splitting the config files into multiple parts makes the whole config more reusable. Especially the possibility to overwrite config settings from imports at config.yaml file is great. But there is a limitation for status buttons. In the merge method you append items into an array. This is ok but makes it impossible to overwrite settings from status buttons.

Example:

FILE display/status/music/mpd.yaml:

display:
  status:
    - mpd:
      mouse_action:
        right_click: stop_playing_song

FILE config.yaml:

display:
  status:
    - mpd:
      mouse_action:
        right_click: launch_gmpc

This won't work because mpd is an item of an array. If I want to overwrite part of this it added a new Item: "status" => [{"mpd" => .... }, {"mpd" => ... }]

This will end in an Exception because the "label"-method is not found in one of these items.

MY SOLUTION: I changed all buttons into an Hash: "status" => {"mpd" => ..., "acpi" => ...}

FILE: display/status.yaml:

CONFIG['display']['status'].each_pair do |name, definition|
  Status.new name, definition
end

Now it's possible to overwrite settings. But now a new position field is necessary. I solved this in config.yaml:

status:
  mpd:
    position: 2
      mouse_action:
        right_click: launch_gmpc
  vpn:
    position: 3

And used the position field as filename: file = "#{@definition['position']||0}-#{name}"

What do you think about that? Any better ideas for the position?

(see commits at http://github.com/nougad/wmiirc)

sunaku commented 14 years ago

make 'display:status' a Ruby 1.9 hash; closed by faa4c5141b1a18088a6c4220f312461004ec66d2

Ruby 1.9 is now required to use this wmiirc because its hashes retains the insertion order of their members and reflect it during iteration.

Without this new Ruby feature, we would need to go back to representing 'display:status' as an array of hashes; thereby losing the ability to address and override things inside a particular status bar applet.