forked from dorkbox/SystemTray
Added GtkPopover. Fixed issue with recursive color definitions. Code
cleanup
This commit is contained in:
parent
eb702327d5
commit
52fc2c3a4a
@ -20,7 +20,9 @@ import static dorkbox.systemTray.SystemTray.logger;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
@ -952,6 +954,7 @@ class Gtk {
|
|||||||
|
|
||||||
Color color1 = color.get();
|
Color color1 = color.get();
|
||||||
if (color1 != null) {
|
if (color1 != null) {
|
||||||
|
System.err.println("COLOR: " + color1);
|
||||||
return color1;
|
return color1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -971,91 +974,82 @@ class Gtk {
|
|||||||
private static Color getFromCss() {
|
private static Color getFromCss() {
|
||||||
String css = getGtkThemeCss();
|
String css = getGtkThemeCss();
|
||||||
if (css != null) {
|
if (css != null) {
|
||||||
// System.err.println("css: " + css);
|
// System.err.println("css: " + css);
|
||||||
|
|
||||||
String[] nodes;
|
String[] nodes;
|
||||||
Tray tray = (Tray) SystemTray.get()
|
Tray tray = (Tray) SystemTray.get()
|
||||||
.getMenu();
|
.getMenu();
|
||||||
|
|
||||||
|
|
||||||
// we care about the following CSS head nodes, and account for MULTIPLE versions, in order of preference.
|
// we care about the following CSS head nodes, and account for multiple versions, in order of preference.
|
||||||
if (tray instanceof _GtkStatusIconNativeTray) {
|
if (tray instanceof _GtkStatusIconNativeTray) {
|
||||||
nodes = new String[] {"gnome-panel-menu-bar", "unity-panel", "PanelMenuBar", ".check"};
|
nodes = new String[] {"GtkPopover", "gnome-panel-menu-bar", "unity-panel", "PanelMenuBar", ".check"};
|
||||||
}
|
}
|
||||||
else if (tray instanceof _AppIndicatorNativeTray) {
|
else if (tray instanceof _AppIndicatorNativeTray) {
|
||||||
nodes = new String[] {"unity-panel", "gnome-panel-menu-bar", "PanelMenuBar", ".check"};
|
nodes = new String[] {"GtkPopover", "unity-panel", "gnome-panel-menu-bar", "PanelMenuBar", ".check"};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// not supported for other types
|
// not supported for other types
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// collect a list of all of the sections that have what we are interested in
|
||||||
|
List<String> sections = new ArrayList<String>();
|
||||||
|
|
||||||
String colorString = null;
|
String colorString = null;
|
||||||
|
|
||||||
// now check the css nodes to see if they contain a combination of what we are looking for.
|
// now check the css nodes to see if they contain a combination of what we are looking for.
|
||||||
colorCheck:
|
colorCheck:
|
||||||
for (String node : nodes) {
|
for (String node : nodes) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i != -1 && colorString == null) {
|
while (i != -1) {
|
||||||
i = css.indexOf(node, i);
|
i = css.indexOf(node, i);
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
int endOfNodeLabels = css.indexOf("{", i);
|
int endOfNodeLabels = css.indexOf("{", i);
|
||||||
|
int endOfSection = css.indexOf("}", endOfNodeLabels + 1) + 1;
|
||||||
|
int endOfSectionTest = css.indexOf("}", i) + 1;
|
||||||
|
|
||||||
String nodeLabel = css.substring(i, endOfNodeLabels);
|
// this makes sure that weird parsing errors don't happen as a result of node keywords appearing in node sections
|
||||||
|
if (endOfSection != endOfSectionTest) {
|
||||||
if (!nodeLabel.contains("menuitem")) {
|
// advance the index
|
||||||
// maybe there is ANOTHER node that has the required classes, this has higher priority than without
|
i = endOfSection;
|
||||||
// advance the counter
|
|
||||||
i = endOfNodeLabels;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int endOfSection = css.indexOf("}", endOfNodeLabels);
|
String nodeLabel = css.substring(i, endOfNodeLabels);
|
||||||
String nodeSection = css.substring(endOfNodeLabels, endOfSection);
|
String nodeSection = css.substring(endOfNodeLabels, endOfSection);
|
||||||
|
|
||||||
|
// if (nodeSection.contains("menu_fg_color")) {
|
||||||
|
// System.err.println(nodeSection);
|
||||||
|
// }
|
||||||
|
|
||||||
int j = nodeSection.indexOf(" color");
|
int j = nodeSection.indexOf(" color");
|
||||||
if (j > -1) {
|
if (j > -1) {
|
||||||
int startOfColorDef = nodeSection.indexOf(":", j) + 1;
|
sections.add(nodeLabel + " " + nodeSection);
|
||||||
int endOfColorDef = nodeSection.indexOf(";", startOfColorDef);
|
|
||||||
colorString = nodeSection.substring(startOfColorDef, endOfColorDef)
|
|
||||||
.trim();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// advance the index
|
|
||||||
i = endOfSection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// advance the index
|
||||||
|
i = endOfSection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for (String section : sections) {
|
||||||
|
// System.err.println("--------------");
|
||||||
|
// System.err.println(section);
|
||||||
|
// System.err.println("--------------");
|
||||||
|
// }
|
||||||
|
|
||||||
if (colorString == null) {
|
if (!sections.isEmpty()) {
|
||||||
colorCheck:
|
String section = sections.get(0);
|
||||||
for (String node : nodes) {
|
int start = section.indexOf("{");
|
||||||
int i = 0;
|
int colorIndex = section.indexOf(" color", start);
|
||||||
while (i != -1 && colorString == null) {
|
|
||||||
i = css.indexOf(node, i);
|
|
||||||
if (i > -1) {
|
|
||||||
int endOfNodeLabels = css.indexOf("{", i);
|
|
||||||
int endOfSection = css.indexOf("}", endOfNodeLabels);
|
|
||||||
String nodeSection = css.substring(endOfNodeLabels, endOfSection);
|
|
||||||
|
|
||||||
int j = nodeSection.indexOf(" color");
|
|
||||||
if (j > -1) {
|
|
||||||
int startOfColorDef = nodeSection.indexOf(":", j) + 1;
|
|
||||||
int endOfColorDef = nodeSection.indexOf(";", startOfColorDef);
|
|
||||||
colorString = nodeSection.substring(startOfColorDef, endOfColorDef)
|
|
||||||
.trim();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// advance the index
|
|
||||||
i = endOfSection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int startOfColorDef = section.indexOf(":", colorIndex) + 1;
|
||||||
|
int endOfColorDef = section.indexOf(";", startOfColorDef);
|
||||||
|
colorString = section.substring(startOfColorDef, endOfColorDef)
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
|
||||||
// hopefully we found it.
|
// hopefully we found it.
|
||||||
if (colorString != null) {
|
if (colorString != null) {
|
||||||
@ -1070,6 +1064,10 @@ class Gtk {
|
|||||||
end = css.lastIndexOf(";", end) + 1; // include the ;
|
end = css.lastIndexOf(";", end) + 1; // include the ;
|
||||||
String colorDefines = css.substring(start, end);
|
String colorDefines = css.substring(start, end);
|
||||||
|
|
||||||
|
// System.err.println("+++++++++++++++++++++++");
|
||||||
|
// System.err.println(colorDefines);
|
||||||
|
// System.err.println("+++++++++++++++++++++++");
|
||||||
|
|
||||||
// since it's a color definition, it will start a very specific way.
|
// since it's a color definition, it will start a very specific way.
|
||||||
String newColorString = colorDefine + " " + colorString;
|
String newColorString = colorDefine + " " + colorString;
|
||||||
|
|
||||||
@ -1086,7 +1084,9 @@ class Gtk {
|
|||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
if (colorSubString.startsWith("@")) {
|
if (colorSubString.startsWith("@")) {
|
||||||
i = endIndex;
|
// have to recursively get the defined color
|
||||||
|
newColorString = colorDefine + " " + colorSubString.substring(1);
|
||||||
|
i = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user