Re: Scheduling WorkRave

Rob Caelers <[email protected]>
Newsgroups gmane.comp.misc.workrave.user
Message-ID <[email protected]>
Hi,

On 22-06-11 12:51, Joe Wells wrote:
> At that time, the answer for Windows was no, but maybe via DBus soon.
> I don't know if this has changed.  (Workrave running on Linux can be
> controlled by both GConf and DBus.)

I'm afraid the situation hasn't changed...

For the time being, you could pretend to be the Workrave toolbar and send 
WM_USER messages to Workrave. I attached an quick&dirty c# program that 
illustrates how this can be done.

Note: This is fully unsupported and is very likely to break in the future (It 
depends on magic values that I do not control).

Groetjes,
   Rob

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev

_______________________________________________
Workrave-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/workrave-user
Program.cs (text/x-csharp, 2.4 KB)
using System;
using System.Text;
using System.Runtime.InteropServices;

namespace WorkraveControl
{
class Program
{
    enum MenuCommand
    {
        MENU_COMMAND_PREFERENCES,
        MENU_COMMAND_EXERCISES,
        MENU_COMMAND_REST_BREAK,
        MENU_COMMAND_MODE_NORMAL,
        MENU_COMMAND_MODE_QUIET,
        MENU_COMMAND_MODE_SUSPENDED,
        MENU_COMMAND_NETWORK_CONNECT,
        MENU_COMMAND_NETWORK_DISCONNECT,
        MENU_COMMAND_NETWORK_LOG,
        MENU_COMMAND_NETWORK_RECONNECT,
        MENU_COMMAND_STATISTICS,
        MENU_COMMAND_ABOUT,
        MENU_COMMAND_MODE_READING,
        MENU_COMMAND_OPEN,
    };

    [DllImport("user32.dll", CharSet = CharSet.Unicode)]
    static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);

    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);

    [DllImport("user32.dll")]
    static extern int GetWindowText(IntPtr window, [In][Out] StringBuilder text, int copyCount);

    [DllImport("user32.dll")]
    static extern int SendMessage(IntPtr window, int message, int wparam, int lparam);

    const int WM_USER = 0x0400;

    static IntPtr RecursiveFindWindow(IntPtr hwnd, String className, String title)
    {
        StringBuilder c = new StringBuilder(100);
        int rc = GetClassName(hwnd, c, c.Capacity);

        StringBuilder t = new StringBuilder(100);
        rc = GetWindowText(hwnd, t, t.Capacity);

        if (c.ToString().Equals(className) && t.ToString().Equals(title))
        {
            return hwnd;
        }
        else
        {
            IntPtr result = IntPtr.Zero;
            IntPtr child = FindWindowEx(hwnd, IntPtr.Zero, null, null);

            while (child != IntPtr.Zero)
            {
                result = RecursiveFindWindow(child, className, title);
                if (result != IntPtr.Zero)
                {
                    return result;
                }

                child = FindWindowEx(hwnd, child, null, null);
            }
            return IntPtr.Zero;
        }
    }

    static void Main(string[] args)
    {
        IntPtr window = RecursiveFindWindow(IntPtr.Zero, "gdkWindowToplevel", "Workrave");
        if (window != IntPtr.Zero)
        {
            SendMessage(window, WM_USER, (int) MenuCommand.MENU_COMMAND_MODE_QUIET, 0);
        }
    }
}
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.