-
Notifications
You must be signed in to change notification settings - Fork 348
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
Refactor notification init #428
Refactor notification init #428
Conversation
src/notification.c
Outdated
*/ | ||
notification *notification_create(void) | ||
{ | ||
return g_malloc0(sizeof(notification)); | ||
} | ||
//FIXME: handle OOM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From glibs docs
If any call to allocate memory fails, the application is terminated. This also means that there is no need to check if the call succeeded.
Means we don't need to handle OOM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. This wasn't clear for me. Only g_try_malloc0 mentions the behavior of g_malloc0
.
src/notification.c
Outdated
/* Color hints */ | ||
n->colors[ColFG] = n->colors[ColFG] | ||
? n->colors[ColFG] | ||
: xctx.colors[ColFG][n->urgency]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like using xctx
inside non-X related functions. Though I guess this will have to stay as-is until the drawing refactor is done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you. But previously, notification_init
also had to access this struct. It's bad, but it's not getting worse (and hopefully gets fixed in refactor drawing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I can't help but feel like all these ternary operators are a bit ugly - what's wrong with a usual if
?
src/notification.c
Outdated
static void notification_extract_urls(notification *n) | ||
{ | ||
// DO markup urls processing here until we split this out correctly | ||
n->urls = notification_extract_markup_urls(&(n->body)); //WHAT THE FUCK!? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the WTF
is here for? - Sure not the best code but not really weird? The contents of that function are many times worse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for mentioning this again.
For me, this function call is against every logic. Why do we put a double pointer to that (and not the notification and turn it into a method like every other method).
I also don't see, why we do have to make changes to the body field there. Markup should be extracted somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
There is a discrepancy between pango and notification spec. Notification spec requires
img
anda
tags, while pango cannot render these (obviously). Asa
tags happen quite regularly, these have to get replaced. Guess, what this method did, too!? -
Let's have these two notifications:
notify-send asdf '<a href="https://github.com/">testname</a>'
n->urls = 0x5555558675f0 "[#1] https://github.com/"
notify-send https://summary-url.de https://internal.com
1: n->urls = 0x555555803980 "https://summary-url.de\nhttps://internal.com"
- Mhmm, same field, different format, 👎
@tsipinakis As I'm tired right now and may have introduced some bugs by myself with the lastest commits, I will review this by myself at first. I will "ping" you by re-requesting a review. OT: I would be able to click on merge for my own PRs, while you requested changes in your current review. Would you mind changing this to make a positive review a neccessity? |
4ac023a
to
8aae64d
Compare
I tweaked the branch restrictions a bit and set it to require a positive review and a passing build to push to master. Thought technically you'd be able to review and approve your own pr, right? |
I guess not. Let's test it! Edit: No, I cannot approve/request changes on my own pull request. I can only add new comments. |
@tsipinakis has enlightened me about the previous functionality of I heavily want to drop this ugly function and replace it with something similar. The specific functionality of adding (Edit: I also found, that notification spec mentions to show it in standard blue underlined text.) Currently I have also removed it in this PR and I'd like to evaluate which path we want to go. |
9c4115e
to
e3238c6
Compare
@tsipinakis Could you please give your opinion here? |
757fce4
to
20644f3
Compare
@@ -30,34 +30,44 @@ typedef struct _actions { | |||
} Actions; | |||
|
|||
typedef struct _notification { | |||
int id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd group this differently: id
and dbus_client
together and appname
, summary
, body
, category
and urgency
in another group since they're the main notification attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grouped it accordingly now.
As I've explained on IRC, as I view it this is because there is no clear indication of which url belongs to which piece of text in the notification when it comes to
We should probably comply with this but it might be a bit misleading since clicking on it won't work with the current implementation. |
Question to understand this: Does pango support $something to know, that the user clicked on a specific textbit? |
20644f3
to
a1db6b2
Compare
Quick google didn't turn up anything - I have no clue. |
6c846eb
to
e0fcbce
Compare
what's better than a linknumber? Put in the actual text! So, if you open up dmenu it will display e.g:
will result in:
This is also more comfortable. |
While it seems like a good suggestion it could break in some scenarios like having a super long link text, or having two links with the same text
would produlce
While the order would give it away somewhat, it's still confusing. |
This is an antipattern and makes linelength increase for nothing
e0fcbce
to
060d6ee
Compare
I agree with you. It's actually confusing. But is it dunst's job to make confusing URLs clear? There is no information lost on dunst's behalf.
Is a long URL currently handled better?
I have to admit, I have only searched for a replacement of the current URL replacement, but I think the solution I came up with is actually much better than the current approach. |
Unboil the spaghetti code and split it into separate methods.
3e27bf9
to
d171ce1
Compare
@tsipinakis I fixed all issues with the URL extraction methods. I added pelnty of tests. Have fun with "Remove a and img tags from msg". ;-) |
3941441
to
56648a5
Compare
if (n->actions) { | ||
n->actions->dmenu_str = NULL; | ||
g_clear_pointer(&n->actions->dmenu_str, g_free); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dmenu_str
is empty at this point so this g_clear_pointer
call is superfluous, and must be 0 since we allocate using g_malloc0
in the case that it contains junk this can cause a crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no guard against calling this function a second time. Setting dmenu_str
solely to NULL
is irresponsible and makes absolutely no sense.
I've done this in every function, which rewrites some fields.
src/markup.c
Outdated
} | ||
|
||
// text between a tags | ||
int text_len = tag2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like you're overusing the ternary operator. Another case that can be a lot more readable with a simple if.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You marked the exact line to let this code look as confusing as possible. 😂
I fully agree with you.
src/markup.c
Outdated
src_e = strstr(src_s + strlen("src=\""), "\""); | ||
|
||
// Move pointer to the actual start | ||
alt_s = alt_s ? alt_s+5 : NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're using strlen
above but +5
here, why the inconsistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yes. That's right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/markup.c
Outdated
// invisible in the replaced text | ||
if (!text_alt || strlen(text_alt) == 0) { | ||
g_free(text_alt); | ||
text_alt = g_strdup("Invisible Image"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using Invisible Image
for everything let's fall back to our previous system, numbers.
Notification with inline image [image #1]
And in dmenu
[#1] url
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Setting the text to "Invisible image" sounds rather mysterious than helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I've seen this just now.
Notification with inline image [image #1]
And in dmenu
[#1] url
Please, no. As a user, I'd question the rationale removing it for links and then adding it again for images. As a user, I'd really insult this dev (myself).
Simply changing it to [Hidden Image]
makes more sense IMO.
test/markup.c
Outdated
|
||
TEST test_markup_strip_img(void) | ||
{ | ||
RUN_TESTp(helper_markup_strip_img, "v <img> img", "v img", NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can tests really be nested like that? I don't see anything indicating so in greatest
docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and no. The code is indicating it, but it's nowhere documented.
It works and it's no problem. In functionality it's far better than calling an extra function.
I wish, there would be an additional layer between test and assertion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok a small background info on this: When an assertion fails, it immediately returns the current function (which should be a test).
As we test multiple strings (done via multiple assertions), a failed assertion breaks the test function. By calling another subtest, the supertest does not fail and will test further for all strings.
c7d376a
to
5e7df83
Compare
While the notification spec allows tags like <a href="...">...</a> and <img src="..." alt="...">, pango cannot parse these tags and therefore these tags should be removed before passed to pango. Also the method notification_extract_markup_urls is not needed anymore, as markup_strip_a can return URLs optionally. This implies, that URL replacement is now indicated via show_indicators for URLs and the dmenu string is in the format of '[text between a tags] URL\n'. This is similarly handled for images, too.
[linktext] can contain arbitary data and also a possible URL, which would get passed to the browser, making the actual URL invalid.
The hints given via DBus are not constants. Therefore the color fields have to get freed during notification cleanup. As it's not possible to disinguish, which field is constant, we have to duplicate the settings on assignment.
Handle replaces_id now via n->id
3d3a719
to
aae73d8
Compare
@tsipinakis I've rebased the fixes already into their commits. If you want to see the actual diff, please see here: bebehei/dunst@refactor-notification_init...refactor-notification_init-backup Edit: Oh, err. The "compare" thing of GitHub isn't working as expected. I'll summarize: Everything, what's changed, is the test_helper test structure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't find anything else, LGTM 👍
Finally! |
…on_init Refactor notification init
Refactors
notification_init
to split it into multiple methods.