Fixed color struct, so now color queries match what C returned
This commit is contained in:
parent
2ca5cdf622
commit
baaaa72079
|
@ -541,7 +541,7 @@ class Gtk {
|
||||||
* appearance. (GTK+ actually keeps a cache of previously created styles, so a new style may not be created.)
|
* appearance. (GTK+ actually keeps a cache of previously created styles, so a new style may not be created.)
|
||||||
*/
|
*/
|
||||||
public static
|
public static
|
||||||
Pointer gtk_rc_get_style(Pointer widget) {
|
GtkStyle gtk_rc_get_style(Pointer widget) {
|
||||||
return Gtk2.gtk_rc_get_style(widget);
|
return Gtk2.gtk_rc_get_style(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -325,7 +325,7 @@ class Gtk2 {
|
||||||
* appearance. (GTK+ actually keeps a cache of previously created styles, so a new style may not be created.)
|
* appearance. (GTK+ actually keeps a cache of previously created styles, so a new style may not be created.)
|
||||||
*/
|
*/
|
||||||
public static native
|
public static native
|
||||||
Pointer gtk_rc_get_style(Pointer widget);
|
GtkStyle gtk_rc_get_style(Pointer widget);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up color_name in the style’s logical color mappings, filling in color and returning TRUE if found, otherwise returning
|
* Looks up color_name in the style’s logical color mappings, filling in color and returning TRUE if found, otherwise returning
|
||||||
|
@ -365,14 +365,28 @@ class Gtk2 {
|
||||||
* by two pango_extents_to_pixels() calls, rounding ink_rect and logical_rect such that the rounded rectangles fully contain the
|
* by two pango_extents_to_pixels() calls, rounding ink_rect and logical_rect such that the rounded rectangles fully contain the
|
||||||
* unrounded one (that is, passes them as first argument to pango_extents_to_pixels()).
|
* unrounded one (that is, passes them as first argument to pango_extents_to_pixels()).
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param layout a PangoLayout
|
* @param layout a PangoLayout
|
||||||
* @param ink_rect rectangle used to store the extents of the layout as drawn or NULL to indicate that the result is not needed.
|
* @param ink_rect rectangle used to store the extents of the layout as drawn or NULL to indicate that the result is not needed.
|
||||||
* @param logical_rect rectangle used to store the logical extents of the layout or NULL to indicate that the result is not needed.
|
* @param logical_rect rectangle used to store the logical extents of the layout or NULL to indicate that the result is not needed.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static native
|
public static native
|
||||||
void pango_layout_get_pixel_extents (Pointer layout, Pointer ink_rect, Pointer logical_rect);
|
void pango_layout_get_pixel_extents(Pointer layout, Pointer ink_rect, Pointer logical_rect);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the GDK (windowing system) resources associated with a widget. For example, widget->window will be created when a widget
|
||||||
|
* is realized. Normally realization happens implicitly; if you show a widget and all its parent containers, then the widget will
|
||||||
|
* be realized and mapped automatically.
|
||||||
|
*
|
||||||
|
* Realizing a widget requires all the widget’s parent widgets to be realized; calling gtk_widget_realize() realizes the widget’s
|
||||||
|
* parents in addition to widget itself. If a widget is not yet inside a toplevel window when you realize it, bad things will happen.
|
||||||
|
*
|
||||||
|
* This function is primarily used in widget implementations, and isn’t very useful otherwise. Many times when you think you might
|
||||||
|
* need it, a better approach is to connect to a signal that will be called after the widget is realized automatically, such as
|
||||||
|
* “draw”. Or simply g_signal_connect() to the “realize” signal.
|
||||||
|
*/
|
||||||
|
public static native
|
||||||
|
void gtk_widget_realize(Pointer widget);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a toplevel container widget that is used to retrieve snapshots of widgets without showing them on the screen.
|
* Creates a toplevel container widget that is used to retrieve snapshots of widgets without showing them on the screen.
|
||||||
|
|
|
@ -36,120 +36,6 @@ class Gtk3 {
|
||||||
public static native
|
public static native
|
||||||
int gtk_get_micro_version();
|
int gtk_get_micro_version();
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a theme from the usual theme paths
|
|
||||||
*
|
|
||||||
* @param name A theme name
|
|
||||||
* @param variant variant to load, for example, "dark", or NULL for the default.
|
|
||||||
*
|
|
||||||
* @return a GtkCssProvider with the theme loaded. This memory is owned by GTK+, and you must not free it.
|
|
||||||
*
|
|
||||||
* @since 3.0
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
Pointer gtk_css_provider_get_named(String name, String variant);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the provider containing the style settings used as a fallback for all widgets.
|
|
||||||
*
|
|
||||||
* @return a GtkCssProvider with the theme loaded. This memory is owned by GTK+, and you must not free it.
|
|
||||||
*
|
|
||||||
* @since 3.0
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
Pointer gtk_css_provider_get_default();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the provider into a string representation in CSS format.
|
|
||||||
* <p>
|
|
||||||
* Using gtk_css_provider_load_from_data() with the return value from this function on a new provider created with
|
|
||||||
* gtk_css_provider_new() will basically create a duplicate of this provider .
|
|
||||||
*
|
|
||||||
* @since 3.2 (released in 2011)
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
String gtk_css_provider_to_string(Pointer provider);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the foreground color for a given state.
|
|
||||||
*
|
|
||||||
* @since 3.0
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
void gtk_style_context_get_color(Pointer context, int stateFlags, Pointer color);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the state used for style matching.
|
|
||||||
*
|
|
||||||
* @since 3.0
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
int gtk_style_context_get_state(Pointer context);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Looks up and resolves a color name in the context color map.
|
|
||||||
*
|
|
||||||
* @since 3.0 (but not in the documentation...)
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
boolean gtk_style_context_lookup_color(Pointer widget, String name, Pointer color);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the style context associated to widget . The returned object is guaranteed to be the same for the lifetime of widget .
|
|
||||||
*
|
|
||||||
* @since 3.0 (but not in the documentation...)
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
Pointer gtk_widget_get_style_context(Pointer widget);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves the context state, so temporary modifications done through gtk_style_context_add_class(), gtk_style_context_remove_class(),
|
|
||||||
* gtk_style_context_set_state(), etc. can quickly be reverted in one go through gtk_style_context_restore().
|
|
||||||
* <p>
|
|
||||||
* The matching call to gtk_style_context_restore() must be done before GTK returns to the main loop.
|
|
||||||
*
|
|
||||||
* @since 3.0
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
void gtk_style_context_save(Pointer context);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Restores context state to a previous stage. See gtk_style_context_save().
|
|
||||||
*
|
|
||||||
* @since 3.0
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
void gtk_style_context_restore(Pointer context);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a style class to context , so posterior calls to gtk_style_context_get() or any of the gtk_render_*() functions will make
|
|
||||||
* use of this new class for styling.
|
|
||||||
*
|
|
||||||
* @since 3.0
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
void gtk_style_context_add_class(Pointer context, String className);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the padding for a given state as a GtkBorder. See gtk_style_context_get() and GTK_STYLE_PROPERTY_PADDING for details.
|
|
||||||
*
|
|
||||||
* @since 3.0
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
void gtk_style_context_get_padding(Pointer context, int state, Pointer border);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the border for a given state as a GtkBorder.
|
|
||||||
* <p>
|
|
||||||
* See gtk_style_context_get_property() and GTK_STYLE_PROPERTY_BORDER_WIDTH for details.
|
|
||||||
*
|
|
||||||
* @since 3.0
|
|
||||||
*/
|
|
||||||
public static native
|
|
||||||
void gtk_style_context_get_border(Pointer context, int state, Pointer border);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the internal scale factor that maps from window coordinates to the actual device pixels. On traditional systems this is 1,
|
* Returns the internal scale factor that maps from window coordinates to the actual device pixels. On traditional systems this is 1,
|
||||||
* but on very high density outputs this can be a higher value (often 2).
|
* but on very high density outputs this can be a higher value (often 2).
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,48 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2015 dorkbox, llc
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package dorkbox.systemTray.jna.linux.structs;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.sun.jna.Structure;
|
|
||||||
|
|
||||||
import dorkbox.util.Keep;
|
|
||||||
|
|
||||||
@Keep
|
|
||||||
public
|
|
||||||
class GParamSpecStruct extends Structure {
|
|
||||||
public
|
|
||||||
class ByValue extends GParamSpecStruct implements Structure.ByValue {}
|
|
||||||
|
|
||||||
|
|
||||||
public
|
|
||||||
class ByReference extends GParamSpecStruct implements Structure.ByReference {}
|
|
||||||
|
|
||||||
|
|
||||||
public GTypeInstanceStruct g_type_instance;
|
|
||||||
|
|
||||||
public String name; /* interned string */
|
|
||||||
// Pointer flags;
|
|
||||||
// double value_type;
|
|
||||||
// double owner_type; /* class or interface using this property */
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected
|
|
||||||
List<String> getFieldOrder() {
|
|
||||||
return Arrays.asList("g_type_instance", "name");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -42,7 +42,7 @@ class GdkColor extends Structure {
|
||||||
public short blue;
|
public short blue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert to positive int (value between 0 and 65535, these are 16 bits per pixel) that is from 0-255
|
* Convert from positive int (value between 0 and 65535, these are 16 bits per pixel) to values from 0-255
|
||||||
*/
|
*/
|
||||||
private static int convert(int inputColor) {
|
private static int convert(int inputColor) {
|
||||||
return (inputColor & 0x0000FFFF >> 8) & 0xFF;
|
return (inputColor & 0x0000FFFF >> 8) & 0xFF;
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2017 dorkbox, llc
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package dorkbox.systemTray.jna.linux.structs;
|
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.sun.jna.Structure;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* https://developer.gnome.org/gdk3/stable/gdk3-RGBA-Colors.html#GdkRGBA
|
|
||||||
*/
|
|
||||||
public
|
|
||||||
class GdkRGBAColor extends Structure {
|
|
||||||
|
|
||||||
// these are from 0.0 to 1.0 inclusive
|
|
||||||
public double red;
|
|
||||||
public double green;
|
|
||||||
public double blue;
|
|
||||||
public double alpha;
|
|
||||||
|
|
||||||
public float red() {
|
|
||||||
return (float) red;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float green() {
|
|
||||||
return (float) green;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float blue() {
|
|
||||||
return (float) blue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public
|
|
||||||
Color getColor() {
|
|
||||||
read(); // have to read the struct members first!
|
|
||||||
return new Color(red(), green(), blue());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected
|
|
||||||
List<String> getFieldOrder() {
|
|
||||||
return Arrays.asList("red", "green", "blue", "alpha");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public
|
|
||||||
class ByValue extends GdkRGBAColor implements Structure.ByValue {}
|
|
||||||
|
|
||||||
|
|
||||||
public
|
|
||||||
class ByReference extends GdkRGBAColor implements Structure.ByReference {}
|
|
||||||
}
|
|
|
@ -46,18 +46,22 @@ class GtkStyle extends Structure {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static
|
public static
|
||||||
class ByReference extends GtkStyle implements Structure.ByReference {}
|
class ByReference extends GtkStyle implements Structure.ByReference {
|
||||||
|
}
|
||||||
|
|
||||||
public
|
public
|
||||||
class ByValue extends GtkStyle implements Structure.ByValue {}
|
class ByValue extends GtkStyle implements Structure.ByValue {
|
||||||
|
}
|
||||||
|
|
||||||
// only list public fields
|
// required, even though it's "private" in the corresponding C code. OTHERWISE the memory offsets are INCORRECT.
|
||||||
|
public GObjectStruct parent_instance;
|
||||||
|
|
||||||
/** fg: foreground for drawing GtkLabel */
|
/** fg: foreground for drawing GtkLabel */
|
||||||
public GdkColor fg[] = new GdkColor[5];
|
public GdkColor fg[] = new GdkColor[5];
|
||||||
|
|
||||||
/** bg: the usual background color, gray by default */
|
/** bg: the usual background color, gray by default */
|
||||||
public GdkColor bg[] = new GdkColor[5];
|
public GdkColor bg[] = new GdkColor[5];
|
||||||
|
|
||||||
public GdkColor light[] = new GdkColor[5];
|
public GdkColor light[] = new GdkColor[5];
|
||||||
public GdkColor dark[] = new GdkColor[5];
|
public GdkColor dark[] = new GdkColor[5];
|
||||||
public GdkColor mid[] = new GdkColor[5];
|
public GdkColor mid[] = new GdkColor[5];
|
||||||
|
@ -69,7 +73,10 @@ class GtkStyle extends Structure {
|
||||||
|
|
||||||
/** base: background when using text, colored white in the default theme. */
|
/** base: background when using text, colored white in the default theme. */
|
||||||
public GdkColor base[] = new GdkColor[5];
|
public GdkColor base[] = new GdkColor[5];
|
||||||
public GdkColor text_aa[] = new GdkColor[5]; /* Halfway between text/base */
|
|
||||||
|
/** Halfway between text/base */
|
||||||
|
public GdkColor text_aa[] = new GdkColor[5];
|
||||||
|
|
||||||
public GdkColor black;
|
public GdkColor black;
|
||||||
public GdkColor white;
|
public GdkColor white;
|
||||||
public Pointer /*PangoFontDescription*/ font_desc;
|
public Pointer /*PangoFontDescription*/ font_desc;
|
||||||
|
@ -77,10 +84,21 @@ class GtkStyle extends Structure {
|
||||||
public int ythickness;
|
public int ythickness;
|
||||||
public Pointer /*cairo_pattern_t*/ background[] = new Pointer[5];
|
public Pointer /*cairo_pattern_t*/ background[] = new Pointer[5];
|
||||||
|
|
||||||
|
public
|
||||||
|
void debug(final int gtkState) {
|
||||||
|
System.err.println("base " + base[gtkState].getColor());
|
||||||
|
System.err.println("text " + text[gtkState].getColor());
|
||||||
|
System.err.println("text_aa " + text_aa[gtkState].getColor());
|
||||||
|
System.err.println("bg " + bg[gtkState].getColor());
|
||||||
|
System.err.println("fg " + fg[gtkState].getColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected
|
protected
|
||||||
List<String> getFieldOrder() {
|
List<String> getFieldOrder() {
|
||||||
return Arrays.asList("fg",
|
return Arrays.asList("parent_instance",
|
||||||
|
"fg",
|
||||||
"bg",
|
"bg",
|
||||||
"light",
|
"light",
|
||||||
"dark",
|
"dark",
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
#include <libappindicator/app-indicator.h>
|
#include <libappindicator/app-indicator.h>
|
||||||
|
|
||||||
|
|
||||||
// gcc example.c `pkg-config --cflags --libs gtk+-2.0 appindicator-0.1` -I/usr/include/libappindicator-0.1/ -o example
|
// gcc example.c `pkg-config --cflags --libs gtk+-2.0 appindicator-0.1` -I/usr/include/libappindicator-0.1/ -o example && ./example
|
||||||
|
|
||||||
// apt libgtk-3-dev install libappindicator3-dev
|
// apt libgtk-3-dev install libappindicator3-dev
|
||||||
// NOTE: there will be warnings, but the file will build and run. NOTE: this will not run as root on ubuntu (no dbus connection back to the normal user)
|
// NOTE: there will be warnings, but the file will build and run. NOTE: this will not run as root on ubuntu (no dbus connection back to the normal user)
|
||||||
// gcc example.c `pkg-config --cflags --libs gtk+-3.0 appindicator3-0.1` -I/usr/include/libappindicator3-0.1/ -o example
|
// gcc example.c `pkg-config --cflags --libs gtk+-3.0 appindicator3-0.1` -I/usr/include/libappindicator3-0.1/ -o example && ./example
|
||||||
|
|
||||||
|
|
||||||
static void activate_action (GtkAction *action);
|
static void activate_action (GtkAction *action);
|
||||||
|
@ -278,6 +278,15 @@ int main (int argc, char **argv)
|
||||||
|
|
||||||
|
|
||||||
menuItem1 = gtk_image_menu_item_new_with_label("menu1");
|
menuItem1 = gtk_image_menu_item_new_with_label("menu1");
|
||||||
|
|
||||||
|
// double check color info
|
||||||
|
GtkStyle *style;
|
||||||
|
style = gtk_rc_get_style(gtk_image_menu_item_new_with_mnemonic("xxx"));
|
||||||
|
|
||||||
|
GdkColor color = style->fg[GTK_STATE_NORMAL];
|
||||||
|
|
||||||
|
fprintf(stderr, "COLOR %s\n", gdk_color_to_string(&color));
|
||||||
|
|
||||||
// g_signal_connect(menuItem1, "button_press_event", G_CALLBACK (gtkCallback), NULL);
|
// g_signal_connect(menuItem1, "button_press_event", G_CALLBACK (gtkCallback), NULL);
|
||||||
gtk_menu_shell_insert(GTK_MENU_SHELL(indicator_menu), menuItem1, 0);
|
gtk_menu_shell_insert(GTK_MENU_SHELL(indicator_menu), menuItem1, 0);
|
||||||
gtk_widget_show(menuItem1);
|
gtk_widget_show(menuItem1);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user