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

Fix(bar): simplify bar config #1224

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

alex-ds13
Copy link
Contributor

@alex-ds13 alex-ds13 commented Jan 10, 2025

Old users will still be able to use the old options, however it should be discouraged or even deprecated to use the following configs:

Configs to remove:

  • work_area_offset inside monitor
  • position
  • frame

If you remove all the options above the bar will still show up with a default height of 50 and a default padding of 10 all around.

If you need to customize the bar height, padding or margin you should use these new options:

New Configs:

  • height: the height you want for the bar itself
  • margin: this option allows you to set a margin around the bar (default: 0). You can either set it like this:
"margin": 10 // It will use a spacing of 10 on all sides of the bar

or like this:

"margin": {
  "vertical": 10 // It will use a spacing of 10 above and below the bar
}

or like this (vertical and horizontal are optional you can set only one axis and the other will be left at default value):

"margin": {
  "vertical": [10, 0], // It will use a spacing of 10 above the bar but no spacing below
  "horizontal": 10,  // It will use a spacing of 10 on the left and right sides of the bar
}

or even like this to specify each side individually:

"margin": {
  "top": 10,
  "bottom": 0,
  "left": 0,
  "right": 0
}
  • padding: this option allows you to set a padding inside the bar (default: 10 on all sides). The higher the padding the smaller the widgets will be, if the vertical padding is set at 0 the widgets will try to fill the entire height of the bar. This option can be set just like the margin above.

Changed Configs:

  • monitor: the monitor config can now be simplified to use a number for the monitor index since you no longer need to specify the work_area_offset. So you can now do this:
"monitor": 0, // remember that the old version still works...

Using these new options after removing the old ones, the bar will automatically calculate the correct work_area_offset for you and apply it. So you don't need to worry about it at all!

Example:

Lets say you wanted a bar like this:
image

Notice that it has some margin on top, but on the bottom is just the normal workspace_padding + container_padding from komorebi. The bar has a height of 80. And a top margin of 10.

BEFORE:

You would need to set the following:

"monitor": {
    "index": 0,
    "work_area_offset": {
        "left": 0,
        "top": 90, // needed to be the bar height + start position y
        "right": 0,
        "bottom": 90 // needed to be the bar height + start position y
    }
  },
  "position": {
      "start": {
          "x": 0,
          "y": 10 // this was to set the margin above
      },
      "end": {
          "x": 1920,
          "y": 80 // this would be the bar height
      }
  },
  "frame": {
      "inner_margin": {
          "x": 10,
          "y": 32 // this would be the vertical padding of the bar
      }
  },
full config
{
  "$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/master/schema.bar.json",
  "monitor": {
    "index": 0,
    "work_area_offset": {
        "left": 0,
        "top": 90,
        "right": 0,
        "bottom": 90
    }
  },
  "position": {
      "start": {
          "x": 0,
          "y": 10
      },
      "end": {
          "x": 1920,
          "y": 80
      }
  },
  "frame": {
      "inner_margin": {
          "x": 10,
          "y": 32
      }
  },
  "grouping": {
      "kind": "Widget",
      "rounding": 16.0,
      "transparency_alpha": 200
  },
  "transparency_alpha": 113,
  "max_label_width": 250,
  "font_family": "JetBrains Mono",
  "theme": {
    "palette": "Base16",
    "name": "TokyoNightStorm",
    "accent": "Base0D"
  },
  "left_widgets": [
    {
      "Komorebi": {
        "workspaces": {
          "enable": true,
          "hide_empty_workspaces": false,
          "display": "Text"
        },
        "layout": {
          "enable": true,
          "display": "Icon"
        }
      }
    }
  ],
  "center_widgets": [
    {
      "Komorebi": {
        "focused_window": {
          "enable": true,
          "display": "IconAndTextOnSelected"
        }
      }
    }
  ],
  "right_widgets": [
    {
      "Battery": {
        "enable": true
      }
    },
    {
      "Date": {
        "enable": true,
        "format": "DayDateMonthYear"
      }
    },
    {
      "Time": {
        "enable": true,
        "format": "TwentyFourHour"
      }
    }
  ]
}

AFTER:

Now you only need this:

  "monitor": 0,
  "height": 80,
  "margin": { "vertical": [10, 0] },
  "padding": { "vertical": 32 },
full config
{
  "$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/master/schema.bar.json",
  "monitor": 0,
  "height": 80,
  "margin": { "vertical": [10, 0] },
  "padding": { "vertical": 32 },
  "grouping": {
      "kind": "Widget",
      "rounding": 16.0,
      "transparency_alpha": 200
  },
  "transparency_alpha": 113,
  "max_label_width": 250,
  "font_family": "JetBrains Mono",
  "theme": {
    "palette": "Base16",
    "name": "TokyoNightStorm",
    "accent": "Base0D"
  },
  "left_widgets": [
    {
      "Komorebi": {
        "workspaces": {
          "enable": true,
          "hide_empty_workspaces": false,
          "display": "Text"
        },
        "layout": {
          "enable": true,
          "display": "Icon"
        }
      }
    }
  ],
  "center_widgets": [
    {
      "Komorebi": {
        "focused_window": {
          "enable": true,
          "display": "IconAndTextOnSelected"
        }
      }
    }
  ],
  "right_widgets": [
    {
      "Battery": {
        "enable": true
      }
    },
    {
      "Date": {
        "enable": true,
        "format": "DayDateMonthYear"
      }
    },
    {
      "Time": {
        "enable": true,
        "format": "TwentyFourHour"
      }
    }
  ]
}

@alex-ds13 alex-ds13 force-pushed the fix(bar)/simplify-bar-config branch 2 times, most recently from dbe7148 to 49121ce Compare January 13, 2025 18:55
@LGUG2Z
Copy link
Owner

LGUG2Z commented Jan 19, 2025

Finally got some time to check this out this weekend. On the whole I'm happy with these changes, but I want to make sure that existing configs will look the same as they did before after applying the changes in this PR

On v0.1.33
image

With this PR:
image

Same configuration file:

{
  "$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/refs/heads/master/schema.bar.json",
  "monitor": {
    "index": 0,
    "work_area_offset": {
      "left": 0,
      "top": 40,
      "right": 0,
      "bottom": 40
    }
  },
  "font_family": "JetBrains Mono",
  "transparency_alpha": 0,
  "position": {
    "start": {
      "x": 20.0,
      "y": 0.0
    },
    "end": {
      "x": 5080.0,
      "y": 50.0
    }
  },
  "grouping": {
    "kind": "Widget",
    "style": "DefaultWithShadowB4O1S3",
    "rounding": 5,
    "transparency_alpha": 255
  },
  "left_widgets": [
    {
      "Komorebi": {
        "workspaces": {
          "enable": true,
          "hide_empty_workspaces": false
        },
        "layout": {
          "enable": false,
          "display": "Icon"
        },
        "focused_window": {
          "enable": true,
          "display": "IconAndText"
        }
      }
    }
  ],
  "center_widgets": [],
  "right_widgets": [
    // {
    //   "Update": {
    //     "enable": true
    //   }
    // },
    {
      "Media": {
        "enable": true
      }
    },
    {
      "Storage": {
        "enable": false
      }
    },
    {
      "Cpu": {
        "enable": true
      }
    },
    {
      "Memory": {
        "enable": true
      }
    },
    {
      "Network": {
        "enable": true,
        "show_default_interface": false,
        "show_total_data_transmitted": false,
        "show_network_activity": true
      }
    },
    {
      "Date": {
        "enable": true,
        "format": "DayDateMonthYear"
      }
    },
    {
      "Time": {
        "enable": true,
        "format": "TwentyFourHour"
      }
    }
  ]
}

@LGUG2Z
Copy link
Owner

LGUG2Z commented Jan 19, 2025

Actually on second thought and after playing around with this a little more, I think that this small discrepancy is fine because it makes everything else more consistent when you change the settings

@LGUG2Z
Copy link
Owner

LGUG2Z commented Jan 19, 2025

Can you do an interactive rebase on this to make it a single commit? 🙏

@alex-ds13 alex-ds13 force-pushed the fix(bar)/simplify-bar-config branch 2 times, most recently from d1b6761 to 69c54fb Compare January 21, 2025 19:06
@alex-ds13
Copy link
Contributor Author

Can you do an interactive rebase on this to make it a single commit? 🙏

Is it ok like this? I can't get a reference to the commits themselves like you do sometimes since they are on my fork...

# This is a combination of 9 commits.
# This is the 1st commit message:

fix(bar): add simplified config for bar

This commit creates a few new config options for the bar that should
make it a lot simpler for new users to configure the bar.
- Remove the need for `position`: if a position is given the bar will
  still use it with priority over the new config. Instead of position
  you can now use the following:
  - `height`: defines the height of the bar (50 by default)
  - `horizontal_margin`: defines the left and right offset of the bar, it
  is the same as setting a `position.start.x` and then remove the same
  amount on `position.end.x`.
  - `vertical_margin`: defines the top and bottom offset of the bar, it is
  the same as setting a `position.start.y` and then add a correct amount
  on the `work_area_offset`.
- Remove the need for `frame`: some new configs were added that take
  priority over the old `frame`. These are:
  - `horizontal_padding`: defines the left and right padding of the bar.
    Similar to `frame.inner_margin.x`.
  - `vertical_padding`: defines the top and bottom padding of the bar.
    Similar to `frame.inner_margin.y`.
- Remove the need for `work_area_offset`: if a `work_area_offset` is
  given then it will take priority, if not, then it will calculate the
  necessary `work_area_offset` using the bar height, position and
  horizontal and vertical margins.

# This is the commit message n.2:

feat(bar): set margin/padding as one or two values

This commit changes the `horizontal_margin`, `vertical_margin`,
`horizontal_padding` and `vertical_padding` to now take a
`SpacingAxisConfig` which can take a single value or two values.
For example, you can set the vertical margin of the bar to add some
spacing above and below like this:
```json
"vertical_margin": 10
```
Which will add a spacing of 10 above and below the bar. Or you can set
it like this:
```json
"vertical_margin": [10, 0]
```
Which will add a spacing of 10 above the bar but no spacing below. You
can even set something like this:
```json
"vertical_margin": [0, -10]
```
To make no spacing above and a negative spacing below to make it so the
tiled windows show right next to the bar. This will basically be
removing the workspace and container padding between the tiled windows
and the bar.

# This is the commit message n.3:

fix(bar): use a right_to_left layout on right side

This commit changes the right area with the right widgets to have a
different layout that is still right_to_left as previously but behaves
much better in regards to its height.

# This is the commit message n.4:

fix(bar): use default bar height

When there is no `work_area_offset` and no `height` on the config it was
using the `BAR_HEIGHT` as default, however the automatica
work_area_offset calculation wasn't being done properly. Now it is!

# This is the commit message n.5:

feat(bar): monitor can be `MonitorConfig` or index

This commit allows the `"monitor":` config to take a `MonitorConfig`
object like it used to or simply a number (index).

# This is the commit message n.6:

docs(schema): update all json schemas

# This is the commit message n.7:

fix(bar): update example bar config

# This is the commit message n.8:

fix(bar): correct work_area_offset on secondary monitors

# This is the commit message n.9:

feat(bar): add multiple options for margin/padding

This commit removes the previous `horizontal_margin`, `vertical_margin`,
`horizontal_padding` and `vertical_padding`, replacing them all with
just `margin` and `padding`.
These new options can be set either with a single value that sets that
spacing on all sides, with an object specifying each individual side or
with an object specifying some "vertical" and/or "horizontal" spacing
which can have a single value, resulting on a symmetric spacing for that
specific axis or two values to define each side of the axis individually.
This commit changes the `rx_gui` from receiving just a notification from
komorebi to now receive a new type `KomorebiEvent` which can be either a
`KomorebiEvent::Notification(komorebi_client::Notification)` or a
`KomorebiEvent::Reconnect`. The `Reconnect` is sent after losing
connection with komorebi and then reconnecting again.
Now on the bar `update` we check for this `rx_gui` if we get a
notification we pass that to the
`KomorebiNotificationState::handle_notification` function just like
before (except now it takes a notification directly instead of taking
the `rx_gui` and checking for some message on the channel). If instead
we get a `Reconnect` we send a `MonitorWorkAreaOffset` socket message to
komorebi to update the work area offset.
@LGUG2Z LGUG2Z merged commit cf79376 into LGUG2Z:master Jan 23, 2025
6 checks passed
LGUG2Z pushed a commit that referenced this pull request Jan 23, 2025
This interactively rebased commit is comprised of the subsequent
individual commits listed further below.

At a high level:

- work_area_offset is now automatically calculated by default
- monitor can now take an index in addition to the previous object
- position can largely be replaced by margin and padding for bars that
  are positioned at the top of the screen
- frame can now largely be replaced by margin and padding for bars that
  are positioned at the top of the screen
- height is now a more intuitive configuration option for setting the
  height of the bar

Detailed explainations and examples are included in the body of PR #1224
on GitHub: #1224

fix(bar): add simplified config for bar

This commit creates a few new config options for the bar that should
make it a lot simpler for new users to configure the bar.

- Remove the need for `position`: if a position is given the bar will
  still use it with priority over the new config. Instead of position
  you can now use the following:
  - `height`: defines the height of the bar (50 by default)
  - `horizontal_margin`: defines the left and right offset of the bar, it
  is the same as setting a `position.start.x` and then remove the same
  amount on `position.end.x`.
  - `vertical_margin`: defines the top and bottom offset of the bar, it is
  the same as setting a `position.start.y` and then add a correct amount
  on the `work_area_offset`.

- Remove the need for `frame`: some new configs were added that take
  priority over the old `frame`. These are:
  - `horizontal_padding`: defines the left and right padding of the bar.
    Similar to `frame.inner_margin.x`.
  - `vertical_padding`: defines the top and bottom padding of the bar.
    Similar to `frame.inner_margin.y`.

- Remove the need for `work_area_offset`: if a `work_area_offset` is
  given then it will take priority, if not, then it will calculate the
  necessary `work_area_offset` using the bar height, position and
  horizontal and vertical margins.

feat(bar): set margin/padding as one or two values

This commit changes the `horizontal_margin`, `vertical_margin`,
`horizontal_padding` and `vertical_padding` to now take a
`SpacingAxisConfig` which can take a single value or two values.

For example, you can set the vertical margin of the bar to add some
spacing above and below like this:

```json
"vertical_margin": 10
```

Which will add a spacing of 10 above and below the bar. Or you can set
it like this:

```json
"vertical_margin": [10, 0]
```

Which will add a spacing of 10 above the bar but no spacing below. You
can even set something like this:

```json
"vertical_margin": [0, -10]
```

To make no spacing above and a negative spacing below to make it so the
tiled windows show right next to the bar. This will basically be
removing the workspace and container padding between the tiled windows
and the bar.

fix(bar): use a right_to_left layout on right side

This commit changes the right area with the right widgets to have a
different layout that is still right_to_left as previously but behaves
much better in regards to its height.

fix(bar): use default bar height

When there is no `work_area_offset` and no `height` on the config it was
using the `BAR_HEIGHT` as default, however the automatica
work_area_offset calculation wasn't being done properly. Now it is!

feat(bar): monitor can be `MonitorConfig` or index

This commit allows the `"monitor":` config to take a `MonitorConfig`
object like it used to or simply a number (index).

docs(schema): update all json schemas

fix(bar): update example bar config

fix(bar): correct work_area_offset on secondary monitors

feat(bar): add multiple options for margin/padding

This commit removes the previous `horizontal_margin`, `vertical_margin`,
`horizontal_padding` and `vertical_padding`, replacing them all with
just `margin` and `padding`.

These new options can be set either with a single value that sets that
spacing on all sides, with an object specifying each individual side or
with an object specifying some "vertical" and/or "horizontal" spacing
which can have a single value, resulting on a symmetric spacing for that
specific axis or two values to define each side of the axis individually.
@alex-ds13 alex-ds13 deleted the fix(bar)/simplify-bar-config branch January 23, 2025 12:15
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

Successfully merging this pull request may close these issues.

2 participants