grim/guifications2

Parents 2bddd57eb34f
Children 76f906fb0623
Noticed that I forgot to get the x11 and win32 specific display files into the cmake build, so moved them into src/ and added them depending on the target
--- a/src/CMakeLists.txt Thu May 23 05:36:49 2013 -0500
+++ b/src/CMakeLists.txt Thu May 23 23:44:20 2013 -0500
@@ -48,6 +48,12 @@
guifications.c
)
+if(WIN32)
+ list(APPEND SOURCES gf_win32_display.c)
+else(WIN32)
+ list(APPEND SOURCES gf_x11_display.c)
+endif(WIN32)
+
add_library(guifications MODULE
${HEADERS}
${SOURCES}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gf_win32_display.c Thu May 23 23:44:20 2013 -0500
@@ -0,0 +1,159 @@
+/*
+ * Guifications - The end all, be all, toaster popup plugin
+ * Copyright (C) 2003-2011 Gary Kramlich
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
+
+#ifndef WINVER
+# define WINVER 0x0500 /* This is Windows 2000 */
+#endif /* WINVER */
+
+#include <windows.h>
+typedef HMONITOR WINAPI GF_MonitorFromRect(LPCRECT,DWORD);
+typedef BOOL WINAPI GF_GetMonitorInfo(HMONITOR,LPMONITORINFO);
+
+/*******************************************************************************
+ * Uses _NET_WORKAREA or SPI_GETWORKAREA to get the geometry of a screen
+ ******************************************************************************/
+static gboolean
+win32_get_workarea_fallback(GdkRectangle *rect) {
+ RECT rcWork;
+ if (SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, FALSE)) {
+ rect->x = rcWork.left;
+ rect->y = rcWork.top;
+ rect->width = rcWork.right - rcWork.left;
+ rect->height = rcWork.bottom - rcWork.top;
+
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ * This will only work on Win98+ and Win2K+
+ */
+static gboolean
+win32_adjust_workarea_multi_monitor(GdkRectangle *rect) {
+ GF_GetMonitorInfo *the_GetMonitorInfo;
+ GF_MonitorFromRect *the_MonitorFromRect;
+ HMODULE hmod;
+ HMONITOR monitor;
+ MONITORINFO info;
+ RECT monitorRect;
+ gint virtual_screen_x, virtual_screen_y;
+
+ monitorRect.left = rect->x;
+ monitorRect.right = rect->x + rect->width;
+ monitorRect.top = rect->y;
+ monitorRect.bottom = rect->y + rect->height;
+
+ /* Convert the coordinates so that 0, 0 is the top left of the Primary
+ * Monitor, not the top left of the virtual screen
+ */
+ virtual_screen_x = GetSystemMetrics(SM_XVIRTUALSCREEN);
+ virtual_screen_y = GetSystemMetrics(SM_YVIRTUALSCREEN);
+
+ if (virtual_screen_x != 0) {
+ monitorRect.left += virtual_screen_x;
+ monitorRect.right += virtual_screen_x;
+ }
+
+ if (virtual_screen_y != 0) {
+ monitorRect.top += virtual_screen_y;
+ monitorRect.bottom += virtual_screen_y;
+ }
+
+ if (!(hmod = GetModuleHandle("user32"))) {
+ return FALSE;
+ }
+
+ if (!(the_MonitorFromRect = (GF_MonitorFromRect*)
+ GetProcAddress(hmod, "MonitorFromRect"))) {
+ return FALSE;
+ }
+
+ if (!(the_GetMonitorInfo = (GF_GetMonitorInfo*)
+ GetProcAddress(hmod, "GetMonitorInfoA"))) {
+ return FALSE;
+ }
+
+ monitor = the_MonitorFromRect(&monitorRect, MONITOR_DEFAULTTONEAREST);
+
+ info.cbSize = sizeof(info);
+ if (!the_GetMonitorInfo(monitor, &info)) {
+ return FALSE;
+ }
+
+ rect->x = info.rcWork.left;
+ rect->y = info.rcWork.top;
+ rect->width = info.rcWork.right - info.rcWork.left;
+ rect->height = info.rcWork.bottom - info.rcWork.top;
+
+ /** Convert the coordinates so that 0, 0 is the top left of the virtual screen,
+ * not the top left of the primary monitor */
+ if (virtual_screen_x != 0) {
+ rect->x += -virtual_screen_x;
+ }
+ if (virtual_screen_y != 0) {
+ rect->y += -virtual_screen_y;
+ }
+
+ return TRUE;
+}
+
+static void
+win32_adjust_workarea(GdkRectangle *rect) {
+ if(!win32_adjust_workarea_multi_monitor(rect)) {
+ if(!win32_get_workarea_fallback(rect)) {
+ /* I don't think this will ever happen */
+ rect->x = 0;
+ rect->y = 0;
+ rect->height = GetSystemMetrics(SM_CXSCREEN);
+ rect->width = GetSystemMetrics(SM_CYSCREEN);
+ }
+ }
+}
+
+gboolean
+gf_display_get_workarea(GdkRectangle *rect) {
+ GdkDisplay *display = NULL;
+ GdkScreen *screen = NULL;
+
+ display = gdk_display_get_default();
+ screen = gdk_display_get_screen(display, disp_screen);
+ gdk_screen_get_monitor_geometry(screen, disp_monitor, rect);
+
+ win32_adjust_workarea(rect);
+
+ return TRUE;
+}
+
+gboolean
+gf_display_screen_saver_is_running(void) {
+ gboolean ret = FALSE;
+
+ if(!SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, (unsigned int) NULL,
+ &ret, FALSE))
+ {
+ ret = FALSE;
+ }
+
+ return ret;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gf_x11_display.c Thu May 23 23:44:20 2013 -0500
@@ -0,0 +1,164 @@
+/*
+ * Guifications - The end all, be all, toaster popup plugin
+ * Copyright (C) 2003-2011 Gary Kramlich
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
+ */
+#include <glib.h>
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+
+#include "gf_display.h"
+
+gboolean
+gf_display_get_workarea(GdkRectangle *rect) {
+ GdkDisplay *g_display = NULL;
+ GdkScreen *g_screen = NULL;
+ Screen *x_screen = NULL;
+ Atom xa_desktops, xa_current, xa_workarea, xa_type;
+ Display *x_display = NULL;
+ Window x_root;
+ guint32 current = 0;
+ gulong *workareas, len, fill;
+ guchar *data;
+ gint format;
+
+ /* get the gdk display */
+ g_display = gdk_display_get_default();
+ if(!g_display)
+ return FALSE;
+
+ /* get the x display from the gdk display */
+ x_display = gdk_x11_display_get_xdisplay(g_display);
+ if(!x_display)
+ return FALSE;
+
+ /* get the screen according to the prefs */
+ g_screen = gdk_display_get_screen(g_display, gf_display_get_screen());
+ if(!g_screen)
+ return FALSE;
+
+ /* get the x screen from the gdk screen */
+ x_screen = gdk_x11_screen_get_xscreen(g_screen);
+ if(!x_screen)
+ return FALSE;
+
+ /* get the root window from the screen */
+ x_root = XRootWindowOfScreen(x_screen);
+
+ /* find the _NET_NUMBER_OF_DESKTOPS atom */
+ xa_desktops = XInternAtom(x_display, "_NET_NUMBER_OF_DESKTOPS", True);
+ if(xa_desktops == None)
+ return FALSE;
+
+ /* find the _NET_CURRENT_DESKTOP atom */
+ xa_current = XInternAtom(x_display, "_NET_CURRENT_DESKTOP", True);
+ if(xa_current == None)
+ return FALSE;
+
+ /* get the current desktop */
+ if(XGetWindowProperty(x_display, x_root, xa_current, 0, 1, False,
+ XA_CARDINAL, &xa_type, &format, &len, &fill,
+ &data) != Success)
+ {
+ return FALSE;
+ }
+
+ if(!data)
+ return FALSE;
+
+ current = *(guint32 *)data;
+ XFree(data);
+
+ /* find the _NET_WORKAREA atom */
+ xa_workarea = XInternAtom(x_display, "_NET_WORKAREA", True);
+ if(xa_workarea == None)
+ return FALSE;
+
+ if(XGetWindowProperty(x_display, x_root, xa_workarea, 0, (glong)(4 * 32),
+ False, AnyPropertyType, &xa_type, &format, &len,
+ &fill, &data) != Success)
+ {
+ return FALSE;
+ }
+
+ /* make sure the type and format are good */
+ if(xa_type == None || format == 0)
+ return FALSE;
+
+ /* make sure we don't have any leftovers */
+ if(fill)
+ return FALSE;
+
+ /* make sure len divides evenly by 4 */
+ if(len % 4 != 0)
+ return FALSE;
+
+ /* it's good, lets use it */
+ workareas = (gulong *)(guint32 *)data;
+
+ rect->x = (guint32)workareas[current * 4];
+ rect->y = (guint32)workareas[current * 4 + 1];
+ rect->width = (guint32)workareas[current * 4 + 2];
+ rect->height = (guint32)workareas[current * 4 + 3];
+
+ /* clean up our memory */
+ XFree(data);
+
+ return TRUE;
+}
+
+gboolean
+gf_display_screen_saver_is_running(void) {
+ GdkDisplay *g_display = NULL;
+ Display *x_display = NULL;
+ static Atom xss, locked, blanked;
+ static gboolean init = FALSE;
+ Atom ratom;
+ gint rtatom;
+ guchar *data = NULL;
+ gulong items, padding;
+ gboolean ret = FALSE;
+
+ g_display = gdk_display_get_default();
+ x_display = gdk_x11_display_get_xdisplay(g_display);
+
+ if(!init) {
+ xss = XInternAtom(x_display,"_SCREENSAVER_STATUS", FALSE);
+ locked = XInternAtom(x_display, "LOCK", FALSE);
+ blanked = XInternAtom(x_display, "BLANK", FALSE);
+ init = TRUE;
+ }
+
+ if(XGetWindowProperty(x_display, GDK_ROOT_WINDOW(), xss, 0, 999, FALSE,
+ XA_INTEGER, &ratom, &rtatom, &items, &padding, &data)
+ == Success)
+ {
+ if(ratom == XA_INTEGER || items >= 3) {
+ guint *item_data = (guint *)data;
+
+ if(item_data[0] == locked || item_data[0] == blanked)
+ ret = TRUE;
+ }
+
+ XFree(data);
+ }
+ return ret;
+
+}
+
--- a/src/win32/gf_win32_display.c Thu May 23 05:36:49 2013 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,159 +0,0 @@
-/*
- * Guifications - The end all, be all, toaster popup plugin
- * Copyright (C) 2003-2011 Gary Kramlich
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-#include <glib.h>
-#include <gtk/gtk.h>
-#include <gdk/gdk.h>
-
-#ifndef WINVER
-# define WINVER 0x0500 /* This is Windows 2000 */
-#endif /* WINVER */
-
-#include <windows.h>
-typedef HMONITOR WINAPI GF_MonitorFromRect(LPCRECT,DWORD);
-typedef BOOL WINAPI GF_GetMonitorInfo(HMONITOR,LPMONITORINFO);
-
-/*******************************************************************************
- * Uses _NET_WORKAREA or SPI_GETWORKAREA to get the geometry of a screen
- ******************************************************************************/
-static gboolean
-win32_get_workarea_fallback(GdkRectangle *rect) {
- RECT rcWork;
- if (SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, FALSE)) {
- rect->x = rcWork.left;
- rect->y = rcWork.top;
- rect->width = rcWork.right - rcWork.left;
- rect->height = rcWork.bottom - rcWork.top;
-
- return TRUE;
- }
- return FALSE;
-}
-
-/**
- * This will only work on Win98+ and Win2K+
- */
-static gboolean
-win32_adjust_workarea_multi_monitor(GdkRectangle *rect) {
- GF_GetMonitorInfo *the_GetMonitorInfo;
- GF_MonitorFromRect *the_MonitorFromRect;
- HMODULE hmod;
- HMONITOR monitor;
- MONITORINFO info;
- RECT monitorRect;
- gint virtual_screen_x, virtual_screen_y;
-
- monitorRect.left = rect->x;
- monitorRect.right = rect->x + rect->width;
- monitorRect.top = rect->y;
- monitorRect.bottom = rect->y + rect->height;
-
- /* Convert the coordinates so that 0, 0 is the top left of the Primary
- * Monitor, not the top left of the virtual screen
- */
- virtual_screen_x = GetSystemMetrics(SM_XVIRTUALSCREEN);
- virtual_screen_y = GetSystemMetrics(SM_YVIRTUALSCREEN);
-
- if (virtual_screen_x != 0) {
- monitorRect.left += virtual_screen_x;
- monitorRect.right += virtual_screen_x;
- }
-
- if (virtual_screen_y != 0) {
- monitorRect.top += virtual_screen_y;
- monitorRect.bottom += virtual_screen_y;
- }
-
- if (!(hmod = GetModuleHandle("user32"))) {
- return FALSE;
- }
-
- if (!(the_MonitorFromRect = (GF_MonitorFromRect*)
- GetProcAddress(hmod, "MonitorFromRect"))) {
- return FALSE;
- }
-
- if (!(the_GetMonitorInfo = (GF_GetMonitorInfo*)
- GetProcAddress(hmod, "GetMonitorInfoA"))) {
- return FALSE;
- }
-
- monitor = the_MonitorFromRect(&monitorRect, MONITOR_DEFAULTTONEAREST);
-
- info.cbSize = sizeof(info);
- if (!the_GetMonitorInfo(monitor, &info)) {
- return FALSE;
- }
-
- rect->x = info.rcWork.left;
- rect->y = info.rcWork.top;
- rect->width = info.rcWork.right - info.rcWork.left;
- rect->height = info.rcWork.bottom - info.rcWork.top;
-
- /** Convert the coordinates so that 0, 0 is the top left of the virtual screen,
- * not the top left of the primary monitor */
- if (virtual_screen_x != 0) {
- rect->x += -virtual_screen_x;
- }
- if (virtual_screen_y != 0) {
- rect->y += -virtual_screen_y;
- }
-
- return TRUE;
-}
-
-static void
-win32_adjust_workarea(GdkRectangle *rect) {
- if(!win32_adjust_workarea_multi_monitor(rect)) {
- if(!win32_get_workarea_fallback(rect)) {
- /* I don't think this will ever happen */
- rect->x = 0;
- rect->y = 0;
- rect->height = GetSystemMetrics(SM_CXSCREEN);
- rect->width = GetSystemMetrics(SM_CYSCREEN);
- }
- }
-}
-
-gboolean
-gf_display_get_workarea(GdkRectangle *rect) {
- GdkDisplay *display = NULL;
- GdkScreen *screen = NULL;
-
- display = gdk_display_get_default();
- screen = gdk_display_get_screen(display, disp_screen);
- gdk_screen_get_monitor_geometry(screen, disp_monitor, rect);
-
- win32_adjust_workarea(rect);
-
- return TRUE;
-}
-
-gboolean
-gf_display_screen_saver_is_running(void) {
- gboolean ret = FALSE;
-
- if(!SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, (unsigned int) NULL,
- &ret, FALSE))
- {
- ret = FALSE;
- }
-
- return ret;
-}
-
--- a/src/x11/gf_x11_display.c Thu May 23 05:36:49 2013 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +0,0 @@
-/*
- * Guifications - The end all, be all, toaster popup plugin
- * Copyright (C) 2003-2011 Gary Kramlich
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
- */
-#include <glib.h>
-#include <gdk/gdk.h>
-#include <gdk/gdkx.h>
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xatom.h>
-
-#include "gf_display.h"
-
-gboolean
-gf_display_get_workarea(GdkRectangle *rect) {
- GdkDisplay *g_display = NULL;
- GdkScreen *g_screen = NULL;
- Screen *x_screen = NULL;
- Atom xa_desktops, xa_current, xa_workarea, xa_type;
- Display *x_display = NULL;
- Window x_root;
- guint32 current = 0;
- gulong *workareas, len, fill;
- guchar *data;
- gint format;
-
- /* get the gdk display */
- g_display = gdk_display_get_default();
- if(!g_display)
- return FALSE;
-
- /* get the x display from the gdk display */
- x_display = gdk_x11_display_get_xdisplay(g_display);
- if(!x_display)
- return FALSE;
-
- /* get the screen according to the prefs */
- g_screen = gdk_display_get_screen(g_display, gf_display_get_screen());
- if(!g_screen)
- return FALSE;
-
- /* get the x screen from the gdk screen */
- x_screen = gdk_x11_screen_get_xscreen(g_screen);
- if(!x_screen)
- return FALSE;
-
- /* get the root window from the screen */
- x_root = XRootWindowOfScreen(x_screen);
-
- /* find the _NET_NUMBER_OF_DESKTOPS atom */
- xa_desktops = XInternAtom(x_display, "_NET_NUMBER_OF_DESKTOPS", True);
- if(xa_desktops == None)
- return FALSE;
-
- /* find the _NET_CURRENT_DESKTOP atom */
- xa_current = XInternAtom(x_display, "_NET_CURRENT_DESKTOP", True);
- if(xa_current == None)
- return FALSE;
-
- /* get the current desktop */
- if(XGetWindowProperty(x_display, x_root, xa_current, 0, 1, False,
- XA_CARDINAL, &xa_type, &format, &len, &fill,
- &data) != Success)
- {
- return FALSE;
- }
-
- if(!data)
- return FALSE;
-
- current = *(guint32 *)data;
- XFree(data);
-
- /* find the _NET_WORKAREA atom */
- xa_workarea = XInternAtom(x_display, "_NET_WORKAREA", True);
- if(xa_workarea == None)
- return FALSE;
-
- if(XGetWindowProperty(x_display, x_root, xa_workarea, 0, (glong)(4 * 32),
- False, AnyPropertyType, &xa_type, &format, &len,
- &fill, &data) != Success)
- {
- return FALSE;
- }
-
- /* make sure the type and format are good */
- if(xa_type == None || format == 0)
- return FALSE;
-
- /* make sure we don't have any leftovers */
- if(fill)
- return FALSE;
-
- /* make sure len divides evenly by 4 */
- if(len % 4 != 0)
- return FALSE;
-
- /* it's good, lets use it */
- workareas = (gulong *)(guint32 *)data;
-
- rect->x = (guint32)workareas[current * 4];
- rect->y = (guint32)workareas[current * 4 + 1];
- rect->width = (guint32)workareas[current * 4 + 2];
- rect->height = (guint32)workareas[current * 4 + 3];
-
- /* clean up our memory */
- XFree(data);
-
- return TRUE;
-}
-
-gboolean
-gf_display_screen_saver_is_running(void) {
- GdkDisplay *g_display = NULL;
- Display *x_display = NULL;
- static Atom xss, locked, blanked;
- static gboolean init = FALSE;
- Atom ratom;
- gint rtatom;
- guchar *data = NULL;
- gulong items, padding;
- gboolean ret = FALSE;
-
- g_display = gdk_display_get_default();
- x_display = gdk_x11_display_get_xdisplay(g_display);
-
- if(!init) {
- xss = XInternAtom(x_display,"_SCREENSAVER_STATUS", FALSE);
- locked = XInternAtom(x_display, "LOCK", FALSE);
- blanked = XInternAtom(x_display, "BLANK", FALSE);
- init = TRUE;
- }
-
- if(XGetWindowProperty(x_display, GDK_ROOT_WINDOW(), xss, 0, 999, FALSE,
- XA_INTEGER, &ratom, &rtatom, &items, &padding, &data)
- == Success)
- {
- if(ratom == XA_INTEGER || items >= 3) {
- guint *item_data = (guint *)data;
-
- if(item_data[0] == locked || item_data[0] == blanked)
- ret = TRUE;
- }
-
- XFree(data);
- }
- return ret;
-
-}
-