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

Criteria #43

Merged
merged 37 commits into from
Jun 13, 2018
Merged

Criteria #43

merged 37 commits into from
Jun 13, 2018

Conversation

vilhalmer
Copy link
Collaborator

@vilhalmer vilhalmer commented Jun 11, 2018

At long last, criteria are here! The syntax is as discussed on #3, and is fairly flexible:

font=SF Mono 9
background-color=#ffffffff
text-color=#000000ff
margin=40,30

[hidden]
font=monospace 11

[urgency=normal app-name="Test\ App"\\\" actionable=true]
font=monospace 11
text-color=#ff0000ff
background-color=#00000000
margin=10

[!actionable]
margin=0
height=500
background-color=#00ff00ff
markup=0

Note that booleans can be specified either as normal, or as bare words (with leading ! to negate). Quoting, escaping, and escaping within quotes works, the literal name of the app in the above example is Test App\". The backslash within the quotes is unnecessary but doesn't hurt anything. Leaving quotes unmatched or backslashes trailing will raise errors. (I bashed on it a lot, but more testing of the parsing is much appreciated!)

Style options within the global section are stored in an empty criteria (which therefore matches everything). It is always the first in the list, and always initialized with the default style options before parsing the configuration.

Things that can currently be overridden:

  • colors
  • margin.{top,bottom} (I have no idea why you would want this.)
  • padding
  • border_size
  • font
  • format
  • default_timeout
  • ignore_timeout
  • markup

Things that don't work yet:

  • width (Currently forced to the surface width by render.)
  • height (I think this is just being completely ignored at the moment?)
  • margin.{left,right} (Need to rework how the surface size is calculated.)
  • actions (You can set it and it's stored, but turning them off doesn't disable them. See also other caveats below.)

Other caveats:

  • I don't know if markup and actions are going to end up being useful. Their enabled status gets sent as part of the XDG bus setup, which means they can only really be either on or off globally.
    • Disabling markup "works" and you see the raw HTML, but since I don't think anyone would ever want this, it might be better to just make it global again. (That way if it's disabled, apps just send plaintext instead.)
    • Disabling actions seems slightly more useful. We would want to advertise it as enabled globally if any criteria has it enabled, and then just ignore interactions with notifications where it has been disabled.
  • The [hidden] section is now fully style-able. However, I'm not happy with the current implementation. I'm going to continue working on a way to make it less of a special case.
  • Because styles are generated for each notification at creation, reloading the config will not update the style of existing notifications. It will, however, update the fake notification that shows the number hidden. I have a few ideas about fixing this, but I'm saving it for later.

Closes #3.

vilhalmer added 30 commits June 8, 2018 19:50
- Style options also mark the style's spec
- hidden section is currently broken
This means that if the global criteria disables a feature, later
critiera cannot reenable it. I'll deal with this later.
This definitely can't stay around either, but good enough for now.
Also add appropriate error messages
I want to refactor this eventually, but I don't know exactly how yet.
@vilhalmer vilhalmer mentioned this pull request Jun 11, 2018
22 tasks
criteria.c Outdated
*value = '\0';
++value;
}
else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: else on same line as }.
This also happens in many other places.

config.c Outdated
void finish_style(struct mako_style *style) {
free(style->font);
free(style->format);
}

// Update `target` with the values specified in `style`. If a failure occurs,
// `target` will remain unchanged.
bool apply_style(struct mako_style *style, struct mako_style *target) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally in C we prefer to have the struct on which the function operates always as the first argument. It seems the comment "target will remain unchanged" is outdated.

Also to make it more obvious that an argument isn't mutated, you can make it const.

return true;
}

bool parse_boolean(const char *string, bool *out) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be reused in config.c too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning on moving this and the existing stuff into a parse.c utility-type file in another PR, which would include making config.c use it. config.c is getting a little bit out of control.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, nice idea. So let's keep it that way for now.

case '"':
state = MAKO_PARSE_STATE_NORMAL;
break;
case ' ':

This comment was marked as resolved.

// string, so that's a safe length to use for the buffer.
int token_max_length = strlen(string) + 1;
char token[token_max_length];
memset(token, 0, token_max_length);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of calling memset, you can initialize token with {0} and all fields will be set to zero.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't use initialization syntax with a variable-length array. :(

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't know that. RIP

criteria.c Outdated
int token_max_length = strlen(string) + 1;
char token[token_max_length];
memset(token, 0, token_max_length);
int token_location = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a size_t

criteria.c Outdated
// Iterate through `criteria_list`, applying the style from each matching
// criteria to `notif`. Returns the number of criteria that matched, or -1 if
// a failure occurs.
int apply_each_criteria(struct wl_list *criteria_list,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can return a ssize_t

Copy link
Owner

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work. I wish I could read PRs like this everyday :)

Apart from these - mostly style and nitpick - issues, I'll test this patch out and it'll probably be ready to merge!

@vilhalmer
Copy link
Collaborator Author

Noting this here mostly to hold myself to it: I'm working on updating the manpage to go with this. I can either tack that on to this PR or post another one soon.

@emersion
Copy link
Owner

Noting this here mostly to hold myself to it: I'm working on updating the manpage to go with this. I can either tack that on to this PR or post another one soon.

Oh, right, I think this should be done in this PR, so that the manpage is not out-of-date.

@emersion
Copy link
Owner

Disabling markup "works" and you see the raw HTML, but since I don't think anyone would ever want this, it might be better to just make it global again.

We could strip HTML tags for instance. But yeah, it's not ideal.

Because styles are generated for each notification at creation, reloading the config will not update the style of existing notifications.

Agreed, this can be filled as a follow-up issue for later.

- _urgency_ (one of "low", "normal", "high")
- _category_ (string)
- _desktop-entry_ (string)
- _actionable_ (boolean)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing "hidden"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Copy link
Owner

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried it, LGTM! :D

@emersion emersion merged commit 4409c6a into emersion:master Jun 13, 2018
@emersion
Copy link
Owner

Thanks, nice work!

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.

Style differently urgent/low priority notifications
3 participants