Conversation
Some applications don't provide their own icons. By default, Openbox sets a generic icon for these applications. Other environments, such as GNOME, instead supply an icon from /usr/share/pixmaps or the icon theme. Openbox's behavior is appropriate when it is running on its own, but when it being used as the window manager in a broader desktop environment, the presence of the default icon prevents the environment from noticing that it needs to provide an icon. This change adds an `<applyDefaultIcon>` configuration option that defaults to `yes` to preserve the standard Openbox behavior. By setting this option to `no`, Openbox will cede responsibility for setting default icons to the desktop environment. Resolves issue Mikachu#21
|
Hold this thought: This was working for me for several hours, but I just had a crash and I'm investigating if it's related to this change or not. |
|
Recompiled with debug symbols and got a more useful crash log. It's crashing in an image resize operation. |
|
I was going to say there hasn’t been a crash report in many years :) Thanks for digging in more |
|
Ah. Okay, so there's a bug in my panel where I'm assigning the icon, and that's triggering an overflow error in To be fair, this is a ridiculous edge case and a WM shouldn't be expected to have flawless behavior in the face of misbehaving clients! But I'll go ahead and fix it while I'm in here. |
1e3a682 to
25f182f
Compare
|
(For the record, the bug was that I was forgetting to prefix the image data with the icon dimensions.) |
|
Okay, having fixed my panel and exercised this PR and my own fallback icon code for a few hours, it's been working great. Ready for review! |
danakj
left a comment
There was a problem hiding this comment.
Thanks, I finally got around to reviewing and left some feedback. It looks good to me then.
| h = data[i++]; | ||
| /* calculate the data size as guint64 to prevent integer | ||
| overflow due to invalid data */ | ||
| guint64 size = w * h; |
There was a problem hiding this comment.
This did not actually calculate the size as a u64; it converts after multiplying. To do this, we need to cast at least one of w or h to u64 first.
size = (guint64)w * h;
The declaration of guint64 size should be up at the top of the function - openbox has followed old C rules in this regard.
| or for zero sized icons. */ | ||
| if (i + w*h > num || w == 0 || h == 0) { | ||
| i += w*h; | ||
| if (i + size > num || size < w || size < h) { |
There was a problem hiding this comment.
With the above corrected, I believe we need to look for overflow here as well of i+size
/* watch for addition overflow, for the data being too small for the
specified size, or for zero sized icons. */
if (i + size < i || i + size > num) {
break;
}
else if (size == 0) {
continue;
}
| w = data[i++]; | ||
| h = data[i++]; | ||
| /* calculate the data size as guint64 to prevent integer | ||
| overflow due to invalid data */ |
There was a problem hiding this comment.
I am not sure that I would call it invalid data. the num here is guint which can be 64-bit. While unreasonably large, a w*h that is larger than 32 bits isn't invalid that I can see.
In fact, https://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html the value is an unsigned long which openbox converts incorrectly to guint, woops. But that's not your problem to solve here :) All this is just to say I think it's not invalid. We just need to ensure we don't go past whatever num we've got here.
So I think we can just drop "due to invalid data" from the comment.
|
|
||
| /* convert it to the right bit order for ObRender */ | ||
| for (j = 0; j < w*h; ++j) | ||
| for (j = 0; j < size; ++j) |
There was a problem hiding this comment.
This will never finish for large size, as j will wrap around before it reaches size and will then go off writing all over memory, so we need to change more types.
as i and j are indexes into the data buffer, which we're comparing against a 64-bit size, we should make i and j also be guint64.
We may be prevented from this by num being a 32-bit value right now but that seems like a mistake anyway, so lets get these types right here at least.
| guint config_theme_window_list_icon_size; | ||
|
|
||
| gchar *config_title_layout; | ||
| gboolean config_apply_default_icon; |
There was a problem hiding this comment.
could we have a consistent ordering across files? this can go right below config_theme_window_list_icon_size here, so move up a couple lines.
There was a problem hiding this comment.
I was looking for a consistent place to put it but the rest of the ordering is inconsistent so I wasn't sure exactly where to place it. I'll go ahead and follow your suggestions because that's probably better than where I did put it.
| config_theme_keepborder = obt_xml_node_bool(n); | ||
| if ((n = obt_xml_find_node(node, "animateIconify"))) | ||
| config_animate_iconify = obt_xml_node_bool(n); | ||
| if ((n = obt_xml_find_node(node, "applyDefaultIcon"))) |
There was a problem hiding this comment.
then this can move down below config_theme_window_list_icon_size as well.
| config_title_layout = g_strdup("NLIMC"); | ||
| config_theme_keepborder = TRUE; | ||
| config_theme_window_list_icon_size = 36; | ||
| config_apply_default_icon = TRUE; |
There was a problem hiding this comment.
and this is already in the right place then.
| /*! Size of icons in focus switching dialogs */ | ||
| extern guint config_theme_window_list_icon_size; | ||
| /*! Set a default icon for windows that lack one */ | ||
| extern gboolean config_apply_default_icon; |
There was a problem hiding this comment.
The new option will need to be added to a few more places:
- The default rc.xml: https://github.com/Mikachu/openbox/blob/53737a844d2bba4bb5892737b05a01d6d06fe84b/data/rc.xml
- The rc.xsd: https://github.com/Mikachu/openbox/blob/53737a844d2bba4bb5892737b05a01d6d06fe84b/data/rc.xsd (it's a type
ob:boolvalue) - And the rc-mouse-focus.xml example config: https://github.com/Mikachu/openbox/blob/53737a844d2bba4bb5892737b05a01d6d06fe84b/doc/rc-mouse-focus.xml
Some applications don't provide their own icons. By default, Openbox sets a generic icon for these applications. Other environments, such as GNOME, instead supply an icon from /usr/share/pixmaps or the icon theme. Openbox's behavior is appropriate when it is running on its own, but when it is being used as the window manager in a broader desktop environment, the presence of the default icon prevents the environment from noticing that it needs to provide an icon.
This change adds an
<applyDefaultIcon>configuration option that defaults toyesto preserve the standard Openbox behavior. By setting this option tono, Openbox will cede responsibility for setting default icons to the desktop environment.Resolves issue #21