mirror of
https://github.com/moparisthebest/FireTray
synced 2024-12-22 05:48:49 -05:00
add testing C files
This commit is contained in:
parent
1e4254b26f
commit
25aa1f535b
@ -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
|
||||
|
45
testing/window_state_event.c
Normal file
45
testing/window_state_event.c
Normal file
@ -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;
|
||||
}
|
65
testing/x11XGetWindowProp.c
Normal file
65
testing/x11XGetWindowProp.c
Normal file
@ -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 */
|
Loading…
Reference in New Issue
Block a user