Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tray
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav
tray
Commits
3872bfcb
Commit
3872bfcb
authored
Jan 09, 2017
by
Serge A. Zaitsev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed memory leak on windows; mac and gtk should be reference-counted
parent
3bfe7aa5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
17 deletions
+30
-17
tray.h
tray.h
+30
-17
No files found.
tray.h
View file @
3872bfcb
...
...
@@ -51,8 +51,7 @@ static int tray_loop(int blocking) {
}
static
void
tray_update
(
struct
tray
*
tray
)
{
app_indicator_set_icon
(
indicator
,
tray
->
icon
);
GtkMenuShell
*
gtk_menu
=
(
GtkMenuShell
*
)
gtk_menu_new
();
GtkMenuShell
*
menu
=
(
GtkMenuShell
*
)
gtk_menu_new
();
for
(
struct
tray_menu
*
m
=
tray
->
menu
;
m
!=
NULL
&&
m
->
text
!=
NULL
;
m
++
)
{
GtkWidget
*
item
;
if
(
strcmp
(
m
->
text
,
"-"
)
==
0
)
{
...
...
@@ -63,12 +62,15 @@ static void tray_update(struct tray *tray) {
gtk_check_menu_item_set_active
(
GTK_CHECK_MENU_ITEM
(
item
),
!!
m
->
checked
);
}
gtk_widget_show
(
item
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
gtk_
menu
),
item
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
menu
),
item
);
if
(
m
->
cb
!=
NULL
)
{
g_signal_connect
(
item
,
"activate"
,
G_CALLBACK
(
_tray_menu_cb
),
m
);
}
}
app_indicator_set_menu
(
indicator
,
GTK_MENU
(
gtk_menu
));
app_indicator_set_icon
(
indicator
,
tray
->
icon
);
// GTK is all about reference counting, so previous menu should be destroyed
// here
app_indicator_set_menu
(
indicator
,
GTK_MENU
(
menu
));
}
static
void
tray_exit
()
{
loop_result
=
-
1
;
}
...
...
@@ -165,7 +167,7 @@ static void tray_exit() { [NSApp terminate:NSApp]; }
static
WNDCLASSEX
wc
;
static
NOTIFYICONDATA
nid
;
static
HWND
hwnd
;
static
HMENU
hmenu
;
static
HMENU
hmenu
=
NULL
;
static
LRESULT
CALLBACK
_tray_wnd_proc
(
HWND
hwnd
,
UINT
msg
,
WPARAM
wparam
,
LPARAM
lparam
)
{
...
...
@@ -241,6 +243,7 @@ static int tray_loop(int blocking) {
}
static
void
tray_update
(
struct
tray
*
tray
)
{
HMENU
prevmenu
=
hmenu
;
int
i
=
0
;
hmenu
=
CreatePopupMenu
();
for
(
struct
tray_menu
*
m
=
tray
->
menu
;
m
!=
NULL
&&
m
->
text
!=
NULL
;
...
...
@@ -248,27 +251,37 @@ static void tray_update(struct tray *tray) {
if
(
strcmp
(
m
->
text
,
"-"
)
==
0
)
{
InsertMenu
(
hmenu
,
i
,
MF_SEPARATOR
,
TRUE
,
""
);
}
else
{
MENUITEMINFO
*
item
=
(
MENUITEMINFO
*
)
malloc
(
sizeof
(
MENUITEMINFO
));
item
->
cbSize
=
sizeof
(
MENUITEMINFO
);
item
->
fMask
=
MIIM_ID
|
MIIM_TYPE
|
MIIM_STATE
|
MIIM_DATA
;
item
->
fType
=
0
;
item
->
fState
=
0
;
MENUITEMINFO
item
;
memset
(
&
item
,
0
,
sizeof
(
item
));
item
.
cbSize
=
sizeof
(
MENUITEMINFO
);
item
.
fMask
=
MIIM_ID
|
MIIM_TYPE
|
MIIM_STATE
|
MIIM_DATA
;
item
.
fType
=
0
;
item
.
fState
=
0
;
if
(
m
->
disabled
)
{
item
->
fState
|=
MFS_DISABLED
;
item
.
fState
|=
MFS_DISABLED
;
}
if
(
m
->
checked
)
{
item
->
fState
|=
MFS_CHECKED
;
item
.
fState
|=
MFS_CHECKED
;
}
item
->
wID
=
i
+
ID_TRAY_FIRST
;
item
->
dwTypeData
=
m
->
text
;
item
->
dwItemData
=
(
ULONG_PTR
)
m
;
item
.
wID
=
i
+
ID_TRAY_FIRST
;
item
.
dwTypeData
=
m
->
text
;
item
.
dwItemData
=
(
ULONG_PTR
)
m
;
InsertMenuItem
(
hmenu
,
i
,
TRUE
,
item
);
InsertMenuItem
(
hmenu
,
i
,
TRUE
,
&
item
);
}
}
SendMessage
(
hwnd
,
WM_INITMENUPOPUP
,
(
WPARAM
)
hmenu
,
0
);
ExtractIconEx
(
tray
->
icon
,
0
,
NULL
,
&
(
nid
.
hIcon
),
1
);
HICON
icon
;
ExtractIconEx
(
tray
->
icon
,
0
,
NULL
,
&
icon
,
1
);
if
(
nid
.
hIcon
)
{
DestroyIcon
(
nid
.
hIcon
);
}
nid
.
hIcon
=
icon
;
Shell_NotifyIcon
(
NIM_MODIFY
,
&
nid
);
if
(
prevmenu
!=
NULL
)
{
DestroyMenu
(
prevmenu
);
}
}
static
void
tray_exit
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment