AppIndicator does not support BOLD text in menus, since we cater to

the lowest common denominator, we remove bold text for status. We
change to use a menu separator to define a "status" at the top of the
 menu
This commit is contained in:
nathan 2016-10-08 23:30:49 +02:00
parent 82ab3fc7bd
commit 87222f8483
5 changed files with 14 additions and 31 deletions

View File

@ -37,7 +37,7 @@ class GtkEntryItem extends GtkEntry implements GCallback {
private volatile Pointer image;
// these are necessary BECAUSE GTK menus look funky as hell when there are some menu entries WITH icons and some WITHOUT
private volatile boolean hasLegitIcon = true;
protected volatile boolean hasLegitIcon = true;
// The mnemonic will ONLY show-up once a menu entry is selected. IT WILL NOT show up before then!
// AppIndicators will only show if you use the keyboard to navigate
@ -52,7 +52,7 @@ class GtkEntryItem extends GtkEntry implements GCallback {
super(parent, Gtk.gtk_image_menu_item_new_with_mnemonic(""));
this.callback = callback;
// cannot be done in a static initializer, because the tray icon size might not yet have been determined
if (transparentIcon == null) {
transparentIcon = ImageUtils.getTransparentImage(ImageUtils.ENTRY_SIZE);
}
@ -149,7 +149,6 @@ class GtkEntryItem extends GtkEntry implements GCallback {
}
Gtk.gtk_menu_item_set_label(_native, text);
Gtk.gtk_widget_show_all(_native);
}

View File

@ -15,10 +15,7 @@
*/
package dorkbox.systemTray.linux;
import com.sun.jna.Pointer;
import dorkbox.systemTray.SystemTrayMenuAction;
import dorkbox.systemTray.linux.jna.Gobject;
import dorkbox.systemTray.linux.jna.Gtk;
// you might wonder WHY this extends MenuEntryItem -- the reason is that an AppIndicator "status" will be offset from everyone else,
@ -31,20 +28,19 @@ class GtkEntryStatus extends GtkEntryItem {
*/
GtkEntryStatus(final GtkMenu parent, final String text) {
super(parent, null);
// need that extra space so it matches windows/mac
hasLegitIcon = false;
setText(text);
}
// called in the GTK thread
@Override
void renderText(final String text) {
// evil hacks abound...
// https://developer.gnome.org/pango/stable/PangoMarkupFormat.html
// AppIndicator strips out markup text.
// https://mail.gnome.org/archives/commits-list/2016-March/msg05444.html
Pointer label = Gtk.gtk_bin_get_child(_native);
Gtk.gtk_label_set_use_markup(label, Gtk.TRUE);
Pointer markup = Gobject.g_markup_printf_escaped("<b>%s</b>", text);
Gtk.gtk_label_set_markup(label, markup);
Gobject.g_free(markup);
Gtk.gtk_menu_item_set_label(_native, text);
Gtk.gtk_widget_show_all(_native);
Gtk.gtk_widget_set_sensitive(_native, Gtk.FALSE);
}

View File

@ -282,14 +282,11 @@ class GtkMenu extends Menu implements MenuEntry {
// now add back other menu entries
synchronized (menuEntries) {
for (int i = 0; i < menuEntries.size(); i++) {
MenuEntry menuEntry__ = menuEntries.get(i);
for (MenuEntry menuEntry__ : menuEntries) {
hasImages |= menuEntry__.hasImage();
}
for (int i = 0; i < menuEntries.size(); i++) {
MenuEntry menuEntry__ = menuEntries.get(i);
for (MenuEntry menuEntry__ : menuEntries) {
// the menu entry looks FUNKY when there are a mis-match of entries WITH and WITHOUT images
if (menuEntry__ instanceof GtkEntry) {
GtkEntry entry = (GtkEntry) menuEntry__;

View File

@ -38,7 +38,7 @@ import dorkbox.systemTray.util.Swt;
*
* Direct-mapping, See: https://github.com/java-native-access/jna/blob/master/www/DirectMapping.md
*/
@SuppressWarnings("Duplicates")
@SuppressWarnings({"Duplicates", "SameParameterValue", "DanglingJavadoc"})
public
class Gtk {
// For funsies to look at, SyncThing did a LOT of work on compatibility in python (unfortunate for us, but interesting).
@ -436,14 +436,6 @@ class Gtk {
public static native void gtk_image_menu_item_set_always_show_image(Pointer menu_item, int forceShow);
public static native Pointer gtk_bin_get_child(Pointer parent);
public static native void gtk_label_set_text(Pointer label, String text);
public static native void gtk_label_set_markup(Pointer label, Pointer markup);
public static native void gtk_label_set_use_markup(Pointer label, int gboolean);
public static native Pointer gtk_status_icon_new();
public static native void gtk_status_icon_set_from_file(Pointer widget, String label);

View File

@ -15,7 +15,6 @@
*/
package dorkbox.systemTray.swing;
import java.awt.Font;
import java.io.File;
import javax.swing.JMenuItem;
@ -34,10 +33,10 @@ class SwingEntryStatus extends SwingEntry implements MenuStatus {
// called in the EDT thread
@Override
void renderText(final String text) {
// AppIndicator strips out markup text, so we disable bold in order to have all of the menus MOSTLY look the same
// https://mail.gnome.org/archives/commits-list/2016-March/msg05444.html
((JMenuItem) _native).setText(text);
Font font = _native.getFont();
Font font1 = font.deriveFont(Font.BOLD);
_native.setFont(font1);
_native.setEnabled(false);
}