[Pkg-mozext-commits] [firetray] 129/399: add testing C files
David Prévot
taffit at alioth.debian.org
Tue Oct 29 18:23:27 UTC 2013
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch dfsg-clean
in repository firetray.
commit 25aa1f535b05e978398b8d7389ee82f079751a30
Author: foudfou <foudil.newbie+git at gmail.com>
Date: Sun Jan 1 19:51:31 2012 +0100
add testing C files
---
testing/Makefile | 8 +++++-
testing/window_state_event.c | 45 +++++++++++++++++++++++++++++
testing/x11XGetWindowProp.c | 65 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 117 insertions(+), 1 deletion(-)
diff --git a/testing/Makefile b/testing/Makefile
index 8ce91e4..b26eda4 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -1,5 +1,5 @@
includes := $(shell pkg-config --libs --cflags gtk+-2.0)
-executables := gtk_icon_example trayicon hide xtypes
+executables := gtk_icon_example trayicon hide xtypes x11XGetWindowProp window_state_event
.PHONY: all
all: $(executables)
@@ -19,3 +19,9 @@ hide: hide.c
xtypes: xtypes.c
gcc $(includes) -o xtypes xtypes.c
+
+x11XGetWindowProp: x11XGetWindowProp.c
+ gcc -Wall x11XGetWindowProp.c -o x11XGetWindowProp -lm -lXext -lX11
+
+window_state_event: window_state_event.c
+ gcc $(includes) -o window_state_event window_state_event.c
diff --git a/testing/window_state_event.c b/testing/window_state_event.c
new file mode 100644
index 0000000..871c8c3
--- /dev/null
+++ b/testing/window_state_event.c
@@ -0,0 +1,45 @@
+#include <gtk/gtk.h>
+
+static void trayIconActivated(GObject *trayIcon, gpointer data);
+static gboolean window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer user_data);
+
+int main(int argc, char *argv[])
+{
+ gtk_init (&argc, &argv);
+
+ GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_size_request (window, 200, 200);
+
+ GtkStatusIcon *trayIcon = gtk_status_icon_new_from_icon_name(GTK_STOCK_MEDIA_STOP);
+ gtk_status_icon_set_tooltip (trayIcon, "My trayicon test");
+ gtk_status_icon_set_visible(trayIcon, FALSE);
+ g_signal_connect(GTK_STATUS_ICON (trayIcon), "activate", GTK_SIGNAL_FUNC (trayIconActivated), window);
+
+
+ g_signal_connect (G_OBJECT (window), "window-state-event", G_CALLBACK (window_state_event), trayIcon);
+
+
+ gtk_widget_show(window);
+ gtk_main ();
+ return 0;
+}
+
+static void trayIconActivated(GObject *trayIcon, gpointer window)
+{
+ gtk_window_deiconify(GTK_WINDOW(window));
+ gtk_widget_show(GTK_WIDGET(window));
+}
+
+static gboolean window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer trayIcon)
+{
+ if(event->changed_mask == GDK_WINDOW_STATE_ICONIFIED && (event->new_window_state == GDK_WINDOW_STATE_ICONIFIED || event->new_window_state == (GDK_WINDOW_STATE_ICONIFIED | GDK_WINDOW_STATE_MAXIMIZED)))
+ {
+ gtk_widget_hide (GTK_WIDGET(widget));
+ gtk_status_icon_set_visible(GTK_STATUS_ICON(trayIcon), TRUE);
+ }
+ else if(event->changed_mask == GDK_WINDOW_STATE_WITHDRAWN && (event->new_window_state == GDK_WINDOW_STATE_ICONIFIED || event->new_window_state == (GDK_WINDOW_STATE_ICONIFIED | GDK_WINDOW_STATE_MAXIMIZED)))
+ {
+ gtk_status_icon_set_visible(GTK_STATUS_ICON(trayIcon), FALSE);
+ }
+ return TRUE;
+}
diff --git a/testing/x11XGetWindowProp.c b/testing/x11XGetWindowProp.c
new file mode 100644
index 0000000..0d6795c
--- /dev/null
+++ b/testing/x11XGetWindowProp.c
@@ -0,0 +1,65 @@
+/*
+ Compiled as:
+ gcc -Wall x11XGetWindowProp.c -o x11XGetWindowProp -lm -lXext -lX11
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+
+int main(void)
+{
+ int screen, idx, stride;
+ int X, Y, W, H;
+ Atom actual;
+ unsigned long count, remaining;
+ int format = 32;
+ int request_size = 4 * sizeof(long);
+ unsigned char *xywh;
+ Display *d = XOpenDisplay(0);
+
+ if (!d) printf("Can't open display: %s",XDisplayName(0));
+ Atom _NET_WORKAREA = XInternAtom(d, "_NET_WORKAREA", 0);
+ screen = DefaultScreen(d);
+
+ /* Find the total screen size (assume X = Y = 0)*/
+ W = DisplayWidth(d, screen);
+ H = DisplayHeight(d, screen);
+ printf("Display Area: W: %d, H: %d\n", W, H);
+
+ /* New query the server to find the usable screen size */
+ if (XGetWindowProperty(d, RootWindow(d, screen),
+ _NET_WORKAREA, 0, request_size, False,
+ XA_CARDINAL, &actual, &format, &count, &remaining, &xywh) || !xywh)
+ {
+ printf("Get workarea failed\n");
+ }
+ else
+ {
+ printf("Got workarea OK\n");
+ printf("format: %d, count: %ld, remaining: %ld\n", format, count, remaining);
+ /* How many bytes per sample? */
+ stride = format / 8;
+ X = *(int*)&xywh[0];
+ Y = *(int*)&xywh[stride];
+ W = *(int*)&xywh[stride * 2];
+ H = *(int*)&xywh[stride * 3];
+
+ /* Now print out the raw xywh byte array for checking */
+ for(idx = 0; idx < request_size; idx++)
+ {
+ printf("%02X ", xywh[idx]);
+ if(!((idx +1)%8)) puts(" ");
+ }
+ /* release the xywh resources */
+ XFree(xywh);
+ printf("Usable Area: X: %d, Y: %d W: %d, H: %d\n", X, Y, W, H);
+ }
+ return 0;
+}
+
+/* End of File */
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firetray.git
More information about the Pkg-mozext-commits
mailing list