1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/*
* tkUnixSysNotify.c implements a "sysnotify" Tcl command which
permits one to post system notifications based on the libnotify API.
*
* Copyright (c) 2020 Kevin Walzer/WordTech Communications LLC.
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tkInt.h"
#include "tkUnixInt.h"
#ifdef HAVE_LIBNOTIFY
#include <libnotify/notify.h>
/*
* Forward declarations for procedures defined in this file.
*/
static void SysNotifyDeleteCmd (void *);
static int SysNotifyCmd(void *, Tcl_Interp *, int, Tcl_Obj * const*);
int SysNotify_Init(Tcl_Interp *);
/*
*----------------------------------------------------------------------
*
* SysNotifyDeleteCmd --
*
* Delete notification and clean up.
*
* Results:
* Window destroyed.
*
* Side effects:
* None.
*
*-------------------------------z---------------------------------------
*/
static void SysNotifyDeleteCmd (
TCL_UNUSED(void *))
{
notify_uninit();
}
/*
*----------------------------------------------------------------------
*
* SysNotifyCreateCmd --
*
* Create tray command and (unreal) window.
*
* Results:
* Icon tray and hidden window created.
*
* Side effects:
* None.
*
*-------------------------------z---------------------------------------
*/
static int SysNotifyCmd(
TCL_UNUSED(void *),
Tcl_Interp *interp,
int objc,
Tcl_Obj *const *objv)
{
const char *title;
const char *message;
const char *icon;
NotifyNotification *notif;
if (objc < 3) {
Tcl_WrongNumArgs(interp, 1, objv, "title message");
return TCL_ERROR;
}
/*
* Pass strings to notification, and use a sane platform-specific
* icon in the alert.
*/
title = Tcl_GetString(objv[1]);
message = Tcl_GetString(objv[2]);
icon = "dialog-information";
/*
* Call to notify_init should go here to prevent test suite failure.
*/
notify_init("Wish");
notif = notify_notification_new(title, message, icon);
notify_notification_show(notif, NULL);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* SysNotify_Init --
*
* Initialize the command.
*
* Results:
* Command initialized.
*
* Side effects:
* None.
*
*-------------------------------z---------------------------------------
*/
int
SysNotify_Init(
Tcl_Interp *interp)
{
Tcl_CreateObjCommand(interp, "_sysnotify", SysNotifyCmd, interp,
SysNotifyDeleteCmd);
return TCL_OK;
}
#endif /* HAVE_LIBNOTIFY */
/*
* Local Variables:
* mode: objc
* c-basic-offset: 4
* fill-column: 79
* coding: utf-8
* End:
*/
|