瀏覽代碼

Add plugin to flash taskbar on windows

Depends-On: Iabc748b6d190b218f771c62a9e713259f81dcc9e
Depends-On: Ief644141e53c63aea5f1e7a405d1623fca5fbd10
Change-Id: Ia4e2bf42b18f88b2138a03a2484e903bfe67df15
Reviewed-on: http://gerrit.dmdirc.com/1867
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.7rc1
Greg Holmes 13 年之前
父節點
當前提交
5812994375

二進制
lib/jna.jar 查看文件


二進制
lib/platform.jar 查看文件


+ 80
- 0
src/com/dmdirc/addons/windowflashing/FlashWindow.java 查看文件

@@ -0,0 +1,80 @@
1
+/*
2
+ * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.windowflashing;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandInfo;
28
+import com.dmdirc.commandparser.CommandType;
29
+import com.dmdirc.commandparser.commands.Command;
30
+import com.dmdirc.commandparser.commands.context.CommandContext;
31
+
32
+/**
33
+ * Command to flash an inactive window under Windows.
34
+ */
35
+public class FlashWindow extends Command implements CommandInfo {
36
+    
37
+    private final WindowFlashing plugin;
38
+
39
+    /**
40
+     * Creates a new flash window command.
41
+     *
42
+     * @param plugin Parent plugin to trigger window flashing
43
+     */
44
+    public FlashWindow(final WindowFlashing plugin) {
45
+        super();
46
+        this.plugin = plugin;
47
+    }
48
+
49
+    /** {@inheritDoc} */
50
+    @Override
51
+    public void execute(final FrameContainer<?> origin,
52
+            final CommandArguments args, final CommandContext context) {
53
+        plugin.flashWindow();
54
+    }
55
+
56
+    /** {@inheritDoc} */
57
+    @Override
58
+    public String getName() {
59
+        return "flashwindow";
60
+    }
61
+
62
+    /** {@inheritDoc} */
63
+    @Override
64
+    public boolean showInHelp() {
65
+        return true;
66
+    }
67
+
68
+    /** {@inheritDoc} */
69
+    @Override
70
+    public String getHelp() {
71
+        return "flashwindow - Flashes the window until activated";
72
+    }
73
+
74
+    /** {@inheritDoc} */
75
+    @Override
76
+    public CommandType getType() {
77
+        return CommandType.TYPE_GLOBAL;
78
+    }
79
+
80
+}

+ 112
- 0
src/com/dmdirc/addons/windowflashing/WindowFlashing.java 查看文件

@@ -0,0 +1,112 @@
1
+/*
2
+ * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.windowflashing;
24
+
25
+import com.dmdirc.addons.ui_swing.MainFrame;
26
+import com.dmdirc.addons.ui_swing.SwingController;
27
+import com.dmdirc.commandparser.CommandManager;
28
+import com.dmdirc.plugins.Plugin;
29
+import com.dmdirc.plugins.PluginManager;
30
+
31
+import com.sun.jna.Native;
32
+import com.sun.jna.NativeLibrary;
33
+import com.sun.jna.Pointer;
34
+import com.sun.jna.platform.win32.User32;
35
+import com.sun.jna.platform.win32.WinDef.HWND;
36
+import com.sun.jna.platform.win32.WinUser.FLASHWINFO;
37
+
38
+/**
39
+ * Native notification plugin to make DMDirc support windows task bar flashing.
40
+ */
41
+public class WindowFlashing extends Plugin {
42
+
43
+    /** Stops the window flashing. */
44
+    private static final int FLASHW_STOP = 0; //NOPMD
45
+    /** Flashes the window caption. */
46
+    private static final int FLASHW_CAPTION = 1; //NOPMD
47
+    /** Flashes the window's taskbar entry. */
48
+    private static final int FLASHW_TRAY = 2; //NOPMD
49
+    /** Flash both the window's caption and taskbar entry. */
50
+    private static final int FLASHW_ALL = 3;
51
+    /** Flash until FLASHW_STOP is set. */
52
+    private static final int FLASHW_TIMER = 4; //NOPMD
53
+    /** Flash until the window gains focus. */
54
+    private static final int FLASHW_TIMERNOFG = 12;
55
+    /** Library instance. */
56
+    private User32 user32;
57
+    /** Flash info object. */
58
+    private FLASHWINFO flashInfo;
59
+    /** Swing main frame. */
60
+    private MainFrame mainFrame;
61
+    /** Flash window command. */
62
+    private FlashWindow flashCommand;
63
+
64
+    /**
65
+     * Flashes an inactive window under windows.
66
+     */
67
+    public void flashWindow() {
68
+        user32.FlashWindowEx(flashInfo);
69
+    }
70
+
71
+    /**
72
+     * Flashes an inactive window under windows, used as a showNotifications
73
+     * exported command
74
+     *
75
+     * @param title Unused
76
+     * @param message Unused
77
+     */
78
+    public void flashNotification(final String title, final String message) {
79
+        flashWindow();
80
+    }
81
+
82
+    /** {@inheritDoc} */
83
+    @Override
84
+    public void onLoad() {
85
+        flashCommand = new FlashWindow(this);
86
+        CommandManager.registerCommand(flashCommand);
87
+        mainFrame = ((SwingController) PluginManager
88
+                .getPluginManager().getPluginInfoByName("ui_swing")
89
+                .getPlugin()).getMainFrame();
90
+        user32 = (User32) Native.loadLibrary("user32", User32.class);
91
+        final HWND hwnd = new HWND();
92
+        final Pointer pointer = Native.getWindowPointer(mainFrame);
93
+        hwnd.setPointer(pointer);
94
+        flashInfo = new FLASHWINFO();
95
+        flashInfo.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
96
+        flashInfo.dwTimeout = 0;
97
+        flashInfo.uCount = Integer.MAX_VALUE;
98
+        flashInfo.hWnd = hwnd;
99
+        flashInfo.cbSize = flashInfo.size();
100
+    }
101
+
102
+    /** {@inheritDoc} */
103
+    @Override
104
+    public void onUnload() {
105
+        CommandManager.unregisterCommand(flashCommand);
106
+        flashCommand = null;
107
+        mainFrame = null;
108
+        user32 = null;
109
+        flashInfo = null;
110
+        NativeLibrary.getInstance("user32").dispose();
111
+    }
112
+}

+ 32
- 0
src/com/dmdirc/addons/windowflashing/plugin.config 查看文件

@@ -0,0 +1,32 @@
1
+# This is a DMDirc configuration file.
2
+
3
+# This section indicates which sections below take key/value
4
+# pairs, rather than a simple list. It should be placed above
5
+# any sections that take key/values.
6
+keysections:
7
+  metadata
8
+  updates
9
+  version
10
+  requires
11
+
12
+metadata:
13
+  author=Greg <greg@dmdirc.com>
14
+  mainclass=com.dmdirc.addons.windowflashing.WindowFlashing
15
+  description=Window flashing
16
+  name=windowflashing
17
+  nicename=Window Flashing
18
+
19
+version:
20
+  friendly=0.1
21
+
22
+updates:
23
+  id=64
24
+
25
+requires:
26
+  os=.*windows.*
27
+
28
+provides:
29
+  windowflash command
30
+
31
+exports:
32
+  flashNotification in com.dmdirc.addons.windowflashing.WindowFlashing as showNotification

Loading…
取消
儲存