@@ -263,7 +263,7 @@ fn setup(dpy: *mut Display) -> State {
263
263
) ,
264
264
numlockmask : 0 ,
265
265
running : true ,
266
- systray : null_mut ( ) ,
266
+ systray : None ,
267
267
xcon : null_mut ( ) ,
268
268
} ;
269
269
@@ -1198,7 +1198,7 @@ fn updatesystrayiconstate(
1198
1198
CurrentTime as i64 ,
1199
1199
code as i64 ,
1200
1200
0 ,
1201
- ( * state. systray ) . win as i64 ,
1201
+ state. systray ( ) . win as i64 ,
1202
1202
XEMBED_EMBEDDED_VERSION as i64 ,
1203
1203
) ;
1204
1204
}
@@ -1241,10 +1241,9 @@ fn updatesystray(state: &mut State) {
1241
1241
if CONFIG . systrayonleft {
1242
1242
x -= sw + state. lrpad / 2 ;
1243
1243
}
1244
- if state. systray . is_null ( ) {
1244
+ if state. systray . is_none ( ) {
1245
1245
// init systray
1246
- state. systray = ecalloc ( 1 , size_of :: < Systray > ( ) ) . cast ( ) ;
1247
- ( * state. systray ) . win = XCreateSimpleWindow (
1246
+ let win = XCreateSimpleWindow (
1248
1247
state. dpy ,
1249
1248
state. root ,
1250
1249
x,
@@ -1258,14 +1257,10 @@ fn updatesystray(state: &mut State) {
1258
1257
wa. event_mask = ButtonPressMask | ExposureMask ;
1259
1258
wa. override_redirect = True ;
1260
1259
wa. background_pixel = state. scheme [ ( Scheme :: Norm , Col :: Bg ) ] . pixel ;
1261
- XSelectInput (
1262
- state. dpy ,
1263
- ( * state. systray ) . win ,
1264
- SubstructureNotifyMask ,
1265
- ) ;
1260
+ XSelectInput ( state. dpy , win, SubstructureNotifyMask ) ;
1266
1261
XChangeProperty (
1267
1262
state. dpy ,
1268
- ( * state . systray ) . win ,
1263
+ win,
1269
1264
state. netatom [ Net :: SystemTrayOrientation as usize ] ,
1270
1265
XA_CARDINAL ,
1271
1266
32 ,
@@ -1276,21 +1271,21 @@ fn updatesystray(state: &mut State) {
1276
1271
) ;
1277
1272
XChangeWindowAttributes (
1278
1273
state. dpy ,
1279
- ( * state . systray ) . win ,
1274
+ win,
1280
1275
CWEventMask | CWOverrideRedirect | CWBackPixel ,
1281
1276
& mut wa,
1282
1277
) ;
1283
- XMapRaised ( state. dpy , ( * state . systray ) . win ) ;
1278
+ XMapRaised ( state. dpy , win) ;
1284
1279
XSetSelectionOwner (
1285
1280
state. dpy ,
1286
1281
state. netatom [ Net :: SystemTray as usize ] ,
1287
- ( * state . systray ) . win ,
1282
+ win,
1288
1283
CurrentTime ,
1289
1284
) ;
1290
1285
if XGetSelectionOwner (
1291
1286
state. dpy ,
1292
1287
state. netatom [ Net :: SystemTray as usize ] ,
1293
- ) == ( * state . systray ) . win
1288
+ ) == win
1294
1289
{
1295
1290
sendevent (
1296
1291
state,
@@ -1299,19 +1294,18 @@ fn updatesystray(state: &mut State) {
1299
1294
StructureNotifyMask as i32 ,
1300
1295
CurrentTime as i64 ,
1301
1296
state. netatom [ Net :: SystemTray as usize ] as i64 ,
1302
- ( * state . systray ) . win as i64 ,
1297
+ win as i64 ,
1303
1298
0_i64 ,
1304
1299
0_i64 ,
1305
1300
) ;
1306
1301
XSync ( state. dpy , False ) ;
1302
+ state. systray = Some ( Systray { win, icons : null_mut ( ) } ) ;
1307
1303
} else {
1308
1304
log:: error!( "unable to obtain system tray" ) ;
1309
- libc:: free ( state. systray . cast ( ) ) ;
1310
- state. systray = null_mut ( ) ;
1311
1305
return ;
1312
1306
}
1313
1307
} // end if !SYSTRAY
1314
- cfor ! ( ( ( w, i) = ( 0 , ( * state. systray) . icons) ;
1308
+ cfor ! ( ( ( w, i) = ( 0 , state. systray( ) . icons) ;
1315
1309
!i. is_null( ) ;
1316
1310
i = ( * i) . next) {
1317
1311
// make sure the background color stays the same
@@ -1330,7 +1324,7 @@ fn updatesystray(state: &mut State) {
1330
1324
x -= w as i32 ;
1331
1325
XMoveResizeWindow (
1332
1326
state. dpy ,
1333
- ( * state. systray ) . win ,
1327
+ state. systray ( ) . win ,
1334
1328
x,
1335
1329
( * m) . by ,
1336
1330
w,
@@ -1347,12 +1341,12 @@ fn updatesystray(state: &mut State) {
1347
1341
} ;
1348
1342
XConfigureWindow (
1349
1343
state. dpy ,
1350
- ( * state. systray ) . win ,
1344
+ state. systray ( ) . win ,
1351
1345
( CWX | CWY | CWWidth | CWHeight | CWSibling | CWStackMode ) as u32 ,
1352
1346
& mut wc,
1353
1347
) ;
1354
- XMapWindow ( state. dpy , ( * state. systray ) . win ) ;
1355
- XMapSubwindows ( state. dpy , ( * state. systray ) . win ) ;
1348
+ XMapWindow ( state. dpy , state. systray ( ) . win ) ;
1349
+ XMapSubwindows ( state. dpy , state. systray ( ) . win ) ;
1356
1350
// redraw background
1357
1351
XSetForeground (
1358
1352
state. dpy ,
@@ -1361,7 +1355,7 @@ fn updatesystray(state: &mut State) {
1361
1355
) ;
1362
1356
XFillRectangle (
1363
1357
state. dpy ,
1364
- ( * state. systray ) . win ,
1358
+ state. systray ( ) . win ,
1365
1359
state. drw . gc ,
1366
1360
0 ,
1367
1361
0 ,
@@ -1378,7 +1372,7 @@ fn wintosystrayicon(state: &State, w: Window) -> *mut Client {
1378
1372
if !CONFIG . showsystray || w == 0 {
1379
1373
return i;
1380
1374
}
1381
- cfor ! ( ( i = ( * state. systray) . icons; !i. is_null( ) && ( * i) . win != w;
1375
+ cfor ! ( ( i = state. systray( ) . icons; !i. is_null( ) && ( * i) . win != w;
1382
1376
i = ( * i) . next) { } ) ;
1383
1377
1384
1378
i
@@ -1703,7 +1697,7 @@ fn updatebars(state: &mut State) {
1703
1697
state. cursors . normal . cursor ,
1704
1698
) ;
1705
1699
if CONFIG . showsystray && m == systraytomon ( state, m) {
1706
- xlib:: XMapRaised ( state. dpy , ( * state. systray ) . win ) ;
1700
+ xlib:: XMapRaised ( state. dpy , state. systray ( ) . win ) ;
1707
1701
}
1708
1702
xlib:: XMapRaised ( state. dpy , ( * m) . barwin ) ;
1709
1703
xlib:: XSetClassHint ( state. dpy , ( * m) . barwin , & mut ch) ;
@@ -1919,14 +1913,14 @@ fn recttomon(
1919
1913
}
1920
1914
}
1921
1915
1922
- fn removesystrayicon ( state : & State , i : * mut Client ) {
1916
+ fn removesystrayicon ( state : & mut State , i : * mut Client ) {
1923
1917
unsafe {
1924
1918
if !CONFIG . showsystray || i. is_null ( ) {
1925
1919
return ;
1926
1920
}
1927
1921
let mut ii: * mut * mut Client ;
1928
1922
cfor ! ( (
1929
- ii = & mut ( * state. systray ) . icons as * mut _;
1923
+ ii = & mut state. systray_mut ( ) . icons as * mut _;
1930
1924
!ii. is_null( ) && * ii != i;
1931
1925
ii = & mut ( * ( * ii) ) . next) { } ) ;
1932
1926
if !ii. is_null ( ) {
@@ -2106,9 +2100,8 @@ fn cleanup(mut state: State) {
2106
2100
}
2107
2101
2108
2102
if CONFIG . showsystray {
2109
- XUnmapWindow ( state. dpy , ( * state. systray ) . win ) ;
2110
- XDestroyWindow ( state. dpy , ( * state. systray ) . win ) ;
2111
- libc:: free ( state. systray . cast ( ) ) ;
2103
+ XUnmapWindow ( state. dpy , state. systray ( ) . win ) ;
2104
+ XDestroyWindow ( state. dpy , state. systray ( ) . win ) ;
2112
2105
}
2113
2106
2114
2107
xlib:: XDestroyWindow ( state. dpy , state. wmcheckwin ) ;
@@ -2772,7 +2765,7 @@ fn getsystraywidth(state: &State) -> c_uint {
2772
2765
let mut i;
2773
2766
if CONFIG . showsystray {
2774
2767
cfor ! ( (
2775
- i = ( * state. systray) . icons;
2768
+ i = state. systray( ) . icons;
2776
2769
!i. is_null( ) ;
2777
2770
( w, i) = ( w + ( * i) . w + config:: CONFIG . systrayspacing as i32 , ( * i) . next) )
2778
2771
{ } ) ;
0 commit comments