11#include <stdlib.h>
2- #include <stdio.h>
32#include <string.h>
43#include <windows.h>
54
@@ -101,7 +100,7 @@ static void trayicon_init(Trayicon *t)
101100static void trayicon_set (Trayicon * t , int number )
102101{
103102 char snumber [2 ];
104- if (number < 0 || number > 9 ) {
103+ if (!( number >= 0 && number <= 9 ) ) {
105104 return ;
106105 }
107106 snumber [0 ] = number + '0' ;
@@ -149,21 +148,20 @@ static void windows_del(Windows *wins, HWND hwnd)
149148{
150149 int i , m ;
151150 for (i = 0 ; i < wins -> count ; i ++ ) {
152- if (wins -> windows [i ] = = hwnd ) {
153- goto remove ;
151+ if (wins -> windows [i ] ! = hwnd ) {
152+ continue ;
154153 }
154+ m = wins -> count - i - 1 ;
155+ if (m > 0 ) {
156+ memcpy (
157+ & (wins -> windows [i ]),
158+ & (wins -> windows [i + 1 ]),
159+ sizeof (HWND )* m
160+ );
161+ }
162+ wins -> count -- ;
163+ break ;
155164 }
156- return ;
157- remove :
158- m = wins -> count - i - 1 ;
159- if (m > 0 ) {
160- memcpy (
161- & (wins -> windows [i ]),
162- & (wins -> windows [i + 1 ]),
163- sizeof (HWND )* m
164- );
165- }
166- wins -> count -- ;
167165}
168166
169167static int is_valid_window (HWND hwnd )
@@ -176,7 +174,7 @@ static int is_valid_window(HWND hwnd)
176174
177175static void register_hotkey (int id , int mod , int vk )
178176{
179- if (RegisterHotKey (NULL , id , mod , vk ) == 0 ) {
177+ if (! RegisterHotKey (NULL , id , mod , vk )) {
180178 MessageBox (NULL , "could not register hotkey" , "error" ,
181179 MB_ICONEXCLAMATION );
182180 exit (1 );
@@ -213,7 +211,7 @@ static void virgo_update(Virgo *v)
213211 desk = & (v -> desktops [i ]);
214212 for (e = 0 ; e < desk -> count ; e ++ ) {
215213 hwnd = desk -> windows [e ];
216- if (GetWindowThreadProcessId (desk -> windows [e ], NULL ) == 0 ) {
214+ if (! GetWindowThreadProcessId (desk -> windows [e ], NULL )) {
217215 windows_del (desk , hwnd );
218216 }
219217 }
@@ -254,7 +252,7 @@ static void virgo_move_to_desk(Virgo *v, int desk)
254252 }
255253 virgo_update (v );
256254 hwnd = GetForegroundWindow ();
257- if (hwnd == NULL || !is_valid_window (hwnd )) {
255+ if (! hwnd || !is_valid_window (hwnd )) {
258256 return ;
259257 }
260258 windows_del (& v -> desktops [v -> current ], hwnd );
@@ -284,7 +282,7 @@ int main(int argc, char **argv)
284282 Virgo v ;
285283 MSG msg ;
286284 virgo_init (& v );
287- while (GetMessage (& msg , NULL , 0 , 0 ) != 0 ) {
285+ while (GetMessage (& msg , NULL , 0 , 0 )) {
288286 if (msg .message != WM_HOTKEY ) {
289287 continue ;
290288 }
0 commit comments