Skip to content

Commit

Permalink
quick workarounds for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmorgner committed Jul 4, 2017
1 parent 0b8d810 commit eaf890f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
9 changes: 9 additions & 0 deletions src/tools/opensc-notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ main (int argc, char **argv)
struct gengetopt_args_info cmdline;
#endif

#ifndef _WIN32
if (cmdline_parser(argc, argv, &cmdline) != 0)
goto err;

Expand Down Expand Up @@ -224,6 +225,14 @@ main (int argc, char **argv)
sc_notify_close();

cmdline_parser_free (&cmdline);
#else
/* FIXME the command line parser fails with our transformed argv. As quick
* fix, we only use daemon mode */
sc_notify_init();
run_daemon = 1;
notify_daemon();
sc_notify_close();
#endif
err:
#ifdef _WIN32
if (argv) {
Expand Down
38 changes: 21 additions & 17 deletions src/ui/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ void sc_notify_close(void)

#if defined(ENABLE_NOTIFY) && defined(_WIN32)

#include "common/compat_strlcpy.h"
#include "invisible_window.h"
#include "wchar_from_char_str.h"
#include <shellapi.h>
#include <shlwapi.h>

static const GUID myGUID = {0x23977b55, 0x10e0, 0x4041, {0xb8,
0x62, 0xb1, 0x95, 0x41, 0x96, 0x36, 0x69}};
Expand All @@ -81,6 +83,12 @@ BOOL delete_icon = TRUE;
#define IDI_CARD_INSERTED 106
UINT const WMAPP_NOTIFYCALLBACK = WM_APP + 1;
static BOOL RestoreTooltip();
#if 1
/* FIXME should be V3 */
#define NOTIFYICONDATA_cbSize NOTIFYICONDATA_V2_SIZE
#else
#define NOTIFYICONDATA_cbSize (sizeof(NOTIFYICONDATA))
#endif

// we need commctrl v6 for LoadIconMetric()
#include <commctrl.h>
Expand All @@ -106,12 +114,16 @@ static const char* lpszClassName = "NOTIFY_CLASS";

static BOOL AddNotificationIcon(void)
{
NOTIFYICONDATA nid;
NOTIFYICONDATA nid = {0};
TCHAR path[MAX_PATH]={0};
BOOL r;

memset(&nid, 0, sizeof nid);
nid.cbSize = sizeof nid;
hwndNotification = create_invisible_window(lpszClassName, WndProc, sc_notify_instance);
if (!hwndNotification) {
return FALSE;
}

nid.cbSize = NOTIFYICONDATA_cbSize;
nid.hWnd = hwndNotification;
// add the icon, setting the icon, tooltip, and callback message.
// the icon will be identified with the GUID
Expand Down Expand Up @@ -141,25 +153,19 @@ static BOOL AddNotificationIcon(void)
nid.uVersion = NOTIFYICON_VERSION_4;
r &= Shell_NotifyIcon(NIM_SETVERSION, &nid);

hwndNotification = create_invisible_window(lpszClassName, WndProc, sc_notify_instance);
if (!hwndNotification) {
r = FALSE;
}

return r;
}

static BOOL DeleteNotificationIcon(void)
{
BOOL r;
NOTIFYICONDATA nid;
NOTIFYICONDATA nid = {0};

if (!delete_icon) {
return FALSE;
}

memset(&nid, 0, sizeof nid);
nid.cbSize = sizeof nid;
nid.cbSize = NOTIFYICONDATA_cbSize;
nid.uFlags = NIF_GUID;
nid.guidItem = myGUID;

Expand All @@ -174,10 +180,9 @@ static BOOL DeleteNotificationIcon(void)
static BOOL RestoreTooltip()
{
// After the balloon is dismissed, restore the tooltip.
NOTIFYICONDATA nid;
NOTIFYICONDATA nid = {0};

memset(&nid, 0, sizeof nid);
nid.cbSize = sizeof nid;
nid.cbSize = NOTIFYICONDATA_cbSize;
nid.uFlags = NIF_SHOWTIP | NIF_GUID;
nid.guidItem = myGUID;

Expand All @@ -187,10 +192,9 @@ static BOOL RestoreTooltip()
static void notify_shell(struct sc_context *ctx,
const char *title, const char *text, WORD icon)
{
NOTIFYICONDATA nid;
NOTIFYICONDATA nid = {0};

memset(&nid, 0, sizeof nid);
nid.cbSize = sizeof nid;
nid.cbSize = NOTIFYICONDATA_cbSize;
nid.uFlags = NIF_GUID;
nid.guidItem = myGUID;

Expand Down

0 comments on commit eaf890f

Please sign in to comment.