Skip to content

Commit

Permalink
Add TrayTip
Browse files Browse the repository at this point in the history
allows to show notifications. This is like calling `notify-send` except that you can also remove all notifications again.
  • Loading branch information
phil294 committed Jul 20, 2023
1 parent 3e70c7e commit c14bad3
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 28 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -55,7 +55,7 @@ AHK_X11 can be used completely without a terminal. You can however if you want u
<details><summary><strong>CLICK TO SEE WHICH COMMANDS ARE IMPLEMENTED AND WHICH ARE MISSING</strong>. Note however that this is not very representative. For example, no `Gui` sub command is included in the listing. For a better overview on what is already done, skim through the <a href="https://phil294.github.io/AHK_X11"><b>FULL DOCUMENTATION HERE</b></a>.</summary>

```diff
DONE ?% (100/220):
DONE ?% (101/220):
+ Else, { ... }, Break, Continue, Return, Exit, GoSub, GoTo, IfEqual, Loop, SetEnv, Sleep, FileCopy,
+ SetTimer, WinActivate, MsgBox, Gui, SendRaw, #Persistent, ExitApp,
+ EnvAdd, EnvSub, EnvMult, EnvDiv, ControlSendRaw, IfWinExist/IfWinNotExist, SetWorkingDir,
Expand All @@ -70,7 +70,7 @@ DONE ?% (100/220):
+ WinGetTitle, WinGetClass, PixelGetColor, CoordMode, GuiControl, ControlGetPos, ControlGetText,
+ WinGet, Input, Loop (parse a string), ToolTip, If var [not] in/contains MatchList, ControlSetText,
+ PixelSearch, #Include, InputBox, ClipWait, EnvSet, SetKeyDelay, SetMouseDelay, MouseClickDrag,
+ #NoTrayIcon
+ #NoTrayIcon, TrayTip

NEW ?% (9/220): (not part of spec or from a more recent version)
@@ Echo, ahk_x11_print_vars, FileRead, RegExGetPos, RegExReplace, EnvGet, Click @@
Expand All @@ -85,7 +85,7 @@ REMOVED ?% (11/220):
# AutoTrim: It's always Off. It would not differentiate between %a_space% and %some_var%.
# It's possible but needs significant work.

TO DO ?% (96/220): alphabetically
TO DO ?% (95/220): alphabetically
- BlockInput, Control, ControlFocus, ControlGet, ControlGetFocus,
- ControlMove,
- DetectHiddenText, DetectHiddenWindows, Drive, DriveGet, DriveSpaceFree,
Expand All @@ -103,7 +103,7 @@ TO DO ?% (96/220): alphabetically
- SetWinDelay, Shutdown, Sort, SoundGet, SoundGetWaveVolume, SoundPlay, SoundSet,
- SoundSetWaveVolume, SplashImage, SplashTextOn, SplashTextOff, SplitPath, StatusBarGetText,
- StatusBarWait, StringCaseSense, StringSplit, StringTrimLeft, StringTrimRight,
- SysGet, Thread, Transform, TrayTip, WinActivateBottom,
- SysGet, Thread, Transform, WinActivateBottom,
- WinGetActiveStats, WinGetActiveTitle,
- WinHide, WinMenuSelectItem, WinMinimizeAll,
- WinMinimizeAllUndo, WinSet, WinSetTitle, WinShow, WinWait, WinWaitActive,
Expand Down
35 changes: 17 additions & 18 deletions docs/index.html
Expand Up @@ -29,7 +29,7 @@ <h1>
<aside class="legend">
<strong style="float:left;margin-right:4px;">Legend:</strong>
<div class="x11"> Green, italic: AHK_X11 only</div>
<div class="rm">Grey, strikethrough: Removed because it makes no sense here</div>
<div class="rm">Grey, strikethrough: Removed because it makes no sense or is impossible</div>
<div class="tbd">Red, strikethrough: Not yet supported, but should be. This is TODO.</div>
</aside>
</div>
Expand Down Expand Up @@ -295,7 +295,7 @@ <h2>Table of contents </h2>
<a href="#ToolTip.htm">ToolTip</a>
</li>
<li>
<a class="tbd" href="#TrayTip.htm">TrayTip</a>
<a href="#TrayTip.htm">TrayTip</a>
</li>
</ul>
</li>
Expand Down Expand Up @@ -1935,12 +1935,12 @@ <h4 class="calibre25">Misc.</h4>
<tbody class="calibre2">
<tr class="calibre3">
<td class="calibre4">A_Cursor</td>
<td class="calibre4"><a id="Variables.htm__Cursor" href="#Variables.htm__Cursor" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a><span class="tbd"> The type of mouse cursor currently being displayed. It will be one of the following words: AppStarting, Arrow, Cross, Help, IBeam, Icon, No, Size, SizeAll, SizeNESW, SizeNS, SizeNWSE, SizeWE, UpArrow, Wait, Unknown. The acronyms used with the size-type cursors are compass directions, e.g. NESW = NorthEast+SouthWest. The hand-shaped cursors (pointing and grabbing) are classfied as Unknown. [requires v1.0.10+]</span></td>
<td class="calibre4"><a id="Variables.htm__Cursor" href="#Variables.htm__Cursor" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a><span class="rm"> The type of mouse cursor currently being displayed. It will be one of the following words: AppStarting, Arrow, Cross, Help, IBeam, Icon, No, Size, SizeAll, SizeNESW, SizeNS, SizeNWSE, SizeWE, UpArrow, Wait, Unknown. The acronyms used with the size-type cursors are compass directions, e.g. NESW = NorthEast+SouthWest. The hand-shaped cursors (pointing and grabbing) are classfied as Unknown. [requires v1.0.10+]</span></td>
</tr>
<tr class="calibre3">
<td class="calibre4">A_CaretX<br class="calibre12" /> A_CaretY</td>
<td class="calibre4">
<div class="tbd">
<div class="rm">
<p class="calibre8"><a id="Caret" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2"></a>The current X and Y coordinates of the caret (text insertion point). [requires v1.0.17+] The coordinates are relative to the active window unless <a href="#CoordMode.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">CoordMode</a> is used to make them relative to the entire screen. If there is no active window or the caret position cannot be determined, these variables are blank.</p>
<p class="calibre8">The following example script allows you to move the caret around to see its current position displayed in an auto-update tooltip. Note that some windows (e.g. certain versions of MS Word) report the same caret position regardless of its actual position.</p>
<p class="calibre8">#Persistent<br class="calibre12" /> SetTimer, WatchCaret, 100<br class="calibre12" /> return<br class="calibre12" /> WatchCaret:<br class="calibre12" /> display_y = %A_CaretY%<br class="calibre12" /> display_y -= 20 ; Move tooltip up a little so as not to hide the caret.<br class="calibre12" /> ToolTip, X%A_CaretX% Y%A_CaretY%, %A_CaretX%, %display_y%<br class="calibre12" /> return</p>
Expand Down Expand Up @@ -2710,7 +2710,7 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<td height="16" class="calibre4">Performs miscellaneous math functions and tasks such as ASCII/Unicode conversion and bitwise operations.</td>
</tr>
<tr class="calibre3">
<td height="16" class="tbd calibre4"><a href="#TrayTip.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">TrayTip</a></td>
<td height="16" class="calibre4"><a href="#TrayTip.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">TrayTip</a></td>
<td height="16" class="calibre4">Creates a balloon message window near the tray icon (requires Windows 2000/XP+).</td>
</tr>
<tr class="calibre3">
Expand Down Expand Up @@ -7201,12 +7201,11 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
</pre>
</div>
</div>
<div class="calibreMain tbd">
<div class="calibreMain">
<div class="calibreEbookContent">
<a id="TrayTip.htm" href="#TrayTip.htm">#</a> <h2 class="calibre17">TrayTip</h2> [v1.0.10+]
<p style="color: #005500 !important;text-decoration:none !important;">For now, please just use RunWait, notify-send title "text text"</p>
<a id="TrayTip.htm" href="#TrayTip.htm">#</a> <h2 class="calibre17">TrayTip</h2>
<hr size="2" class="calibre24" />
<p class="calibre8">Creates a balloon message window near the tray icon (requires Windows 2000/XP+).</p>
<p class="calibre8">Creates a balloon message window <span class="rm">near the tray icon</span> <span class="x11">Shows a popup, typically at the top right corner of the screen.</span> <span class="x11">Multiple notifications can be shown at the same time.</span></p>
<table cellspacing="5" width="100%" class="calibre28">
<tbody class="calibre2">
<tr class="calibre3">
Expand All @@ -7223,23 +7222,23 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<tr class="calibre3">
<td class="calibre4">Title</td>
<td class="calibre4">
<p class="calibre8">If all parameters are omitted, any TrayTip window currently displayed will be removed.</p>
<p class="calibre8">Otherwise, this parameter is the title of the window, which can be up to 63 characters long (characters beyond this length are not shown).</p>
<p class="calibre8">If all parameters are omitted, <span class="rm">any TrayTip window</span> <span class="x11">all existing TrayTip windows</span> currently displayed will be removed.</p>
<p class="calibre8">Otherwise, this parameter is the title of the window, <span class="rm">which can be up to 63 characters long (characters beyond this length are not shown).</span></p>
<p class="calibre8">If <em class="calibre21">Title</em> is blank, the title line will be entirely omitted from the balloon window, making it vertically shorter.</p>
</td>
</tr>
<tr class="calibre3">
<td width="15%" class="calibre4">Text</td>
<td width="85%" class="calibre4">
<p class="calibre8">The message to display, which appears beneath <em class="calibre21">Title</em>. Only the first 255 characters of <em class="calibre21">Text</em> will be displayed. Carriage return (`r) or linefeed (`n) may be used to create multiple lines of text. For example: Line1`nLine2 </p>
<p class="calibre8">The message to display, which appears beneath <em class="calibre21">Title</em>. <span class="rm">Only the first 255 characters of <em class="calibre21">Text</em> will be displayed.</span> Carriage return (`r) or linefeed (`n) may be used to create multiple lines of text. For example: Line1`nLine2 </p>
<p class="calibre8">If this parameter is omitted or blank, any TrayTip window currently displayed will be removed. </p>
</td>
</tr>
<tr class="calibre3">
<td width="15%" class="calibre4">Seconds</td>
<td width="85%" class="calibre4">
<p class="calibre8">The approximate number of seconds to display the window, after which it will be automatically removed by the OS. Specifying a number less than 10 or greater than 30 will usually cause the minimum (10) or maximum (30) display time to be used instead. If blank or omitted, the minimum time will usually be used. </p>
<p class="calibre8">This setting is currently unreliable due to the nature of its handling by the OS. To have precise control over how long the TrayTip is displayed, use the <a href="#Sleep.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Sleep</a> command followed by TrayTip with no parameters, or use <a href="#SetTimer.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetTimer</a> as illustrated in the Examples section below.</p>
<p class="calibre8">The <span class="rm">approximate</span> number of seconds to display the window, after which it will be automatically removed by the OS. <span class="rm">Specifying a number less than 10 or greater than 30 will usually cause the minimum (10) or maximum (30) display time to be used instead.</span> <span class="rm">If blank or omitted, the minimum time will usually be used.</span> <span class="x11">If blank, the default OS-wide configured nofification duration will be used. If set to 0, it will never expire. If set to -1, the library default will be used which appears to be 10 seconds (?).</span> </p>
<p class="calibre8"><span class="rm">This setting is currently unreliable due to the nature of its handling by the OS.</span> To have precise control over how long the TrayTip is displayed, use the <a href="#Sleep.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Sleep</a> command followed by TrayTip with no parameters, or use <a href="#SetTimer.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetTimer</a> as illustrated in the Examples section below.</p>
</td>
</tr>
<tr class="calibre3">
Expand All @@ -7255,9 +7254,8 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
</table>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">Remarks</strong></p>
<p class="calibre8"> TrayTip requires Windows 2000/XP+.</p>
<p class="calibre8">TrayTip windows cannot be shown if the script lacks a tray icon (via <a href="#h_NoTrayIcon.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#NoTrayIcon</a> or <em class="calibre21"><a href="#Menu.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Menu</a>, tray, NoIcon</em>). Similarly, if the following REG_DWORD value exists and has been set to 0, TrayTip will not function:<br class="calibre12" /> HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced &gt;&gt; EnableBalloonTips</p>
<p class="calibre8">Windows XP usually plays a sound when displaying a balloon tip. This sound can be disabled by adding 16 to the <em class="calibre21">Options </em> parameter.</p>
<p class="calibre8 rm">TrayTip windows cannot be shown if the script lacks a tray icon (via <a href="#h_NoTrayIcon.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#NoTrayIcon</a> or <em class="calibre21"><a href="#Menu.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Menu</a>, tray, NoIcon</em>). Similarly, if the following REG_DWORD value exists and has been set to 0, TrayTip will not function:<br class="calibre12" /> HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced &gt;&gt; EnableBalloonTips</p>
<p class="calibre8 rm">Windows XP usually plays a sound when displaying a balloon tip. This sound can be disabled by adding 16 to the <em class="calibre21">Options </em> parameter.</p>
<p class="calibre8"> </p>
<p class="calibre8"> <strong class="calibre14">Related</strong></p>
<p class="calibre8"><a href="#ToolTip.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">ToolTip</a>, <a href="#SetTimer.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SetTimer</a>, <a href="#SplashTextOn.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SplashTextOn</a>, <a href="#MsgBox.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">MsgBox</a>, <a href="#InputBox.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">InputBox</a>, <a href="#FileSelectFile.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">FileSelectFile</a>, <a href="#FileSelectFolder.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">FileSelectFolder</a></p>
Expand All @@ -7284,7 +7282,8 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
return

RefreshTrayTip:
TrayTip, Refreshed TrayTip, This is a more permanent TrayTip., , 16
TrayTip
TrayTip, Refreshed TrayTip, This is a more permanent TrayTip.
return

</pre>
Expand Down
14 changes: 9 additions & 5 deletions shard.lock
Expand Up @@ -2,7 +2,7 @@ version: 2.0
shards:
atspi:
git: https://github.com/phil294/atspi.cr.git
version: 0.12.0+git.commit.dc31620f1cc66f9fce2f4d0ed3114dc22a15ccf1
version: 0.12.0+git.commit.7aec8d3604313da415e54e654c1dc6b33ae05d8d

cron_parser:
git: https://github.com/kostya/cron_parser.git
Expand All @@ -14,27 +14,31 @@ shards:

gi-crystal:
git: https://github.com/hugopl/gi-crystal.git
version: 0.16.0+git.commit.2874e31eaa7339cb4e0d6b504c19b872c0c202c4
version: 0.17.0

gio:
git: https://github.com/hugopl/gio.cr.git
version: 0.1.0

gtk3:
git: https://github.com/phil294/gtk3.cr.git
version: 0.14.0+git.commit.0c3f29395a7e543a17cda38b5bf9edf18765994d
version: 0.14.0+git.commit.362ff38bc33a3406d3d8ea95475b04062399d644

harfbuzz:
git: https://github.com/hugopl/harfbuzz.cr.git
version: 0.1.0
version: 0.2.0

notify:
git: https://github.com/phil294/notify.cr.git
version: 0.12.0+git.commit.0c9880e6169e09f0db1cb40432e0b76651d15ad3

pango:
git: https://github.com/hugopl/pango.cr.git
version: 0.2.0

tasker:
git: https://github.com/spider-gazelle/tasker.git
version: 2.0.7
version: 2.1.4

x11:
git: https://github.com/tamasszekeres/x11-cr.git
Expand Down
4 changes: 3 additions & 1 deletion shard.yml
Expand Up @@ -26,4 +26,6 @@ dependencies:
gtk3:
github: phil294/gtk3.cr
atspi:
github: phil294/atspi.cr
github: phil294/atspi.cr
notify:
github: phil294/notify.cr
29 changes: 29 additions & 0 deletions src/cmd/gtk/tray-tip.cr
@@ -0,0 +1,29 @@
# TrayTip [, Title, Text, Seconds, Options]
class Cmd::Gtk::Gui::TrayTip < Cmd::Base
def self.min_args; 0 end
def self.max_args; 4 end
class_property notifications = [] of Notify::Notification
def run(thread, args)
if args.size < 2
thread.runner.display.gtk.act do
@@notifications.each &.close
end
@@notifications.clear
return
end
icon = case args[3]?
when nil then nil
when "1" then "dialog-information"
when "2" then "dialog-warning"
when "3" then "dialog-error"
else nil end
timeout = args[2]? && args[2].to_f?
gtk_notification = thread.runner.display.gtk.act do
notification = Notify::Notification.new(args[0], args[1], icon)
notification.timeout = (timeout.to_f * 1000).to_i if timeout
notification.show()
notification
end
@@notifications << gtk_notification
end
end
2 changes: 2 additions & 0 deletions src/run/display/gtk.cr
@@ -1,5 +1,6 @@
require "gtk3"
require "../../logo"
require "notify"

module Run
# Please note that all GUI logic needs to happen on the same worker thread where `run` was called
Expand Down Expand Up @@ -316,6 +317,7 @@ module Run
".to_slice)
end
init_menu(runner)
Notify.init @default_title
end
def tray
with self yield @tray.not_nil!, @tray_menu.not_nil!
Expand Down

0 comments on commit c14bad3

Please sign in to comment.