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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
|
/*
DeaDBeeF - ultimate music player for GNU/Linux systems with X11
Copyright (C) 2009 Alexey Yakovenko
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <ctype.h>
#include <assert.h>
#include <sys/time.h>
#include "gtkplaylist.h"
#include "callbacks.h"
#include "interface.h"
#include "support.h"
#include "search.h"
#include "progress.h"
#include "drawing.h"
#include "session.h"
#include "deadbeef.h"
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))
#define PL_HEAD(iter) (deadbeef->pl_get_first(iter))
#define PL_TAIL(iter) (deadbeef->pl_get_last(iter))
#define PL_NEXT(it, iter) (deadbeef->pl_get_next(it, iter))
#define PL_PREV(it, iter) (deadbeef->pl_get_prev(it, iter))
#define SELECTED(it) (deadbeef->pl_is_selected(it))
#define SELECT(it, sel) (deadbeef->pl_set_selected(it,sel))
#define VSELECT(it, sel) {deadbeef->pl_set_selected(it,sel);gtk_pl_redraw_item_everywhere (it);}
extern DB_functions_t *deadbeef; // defined in gtkui.c
//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
#define trace(fmt,...)
// debug function for gdk_draw_drawable
static inline void
draw_drawable (GdkDrawable *window, GdkGC *gc, GdkDrawable *drawable, int x1, int y1, int x2, int y2, int w, int h) {
// printf ("dd: %p %p %p %d %d %d %d %d %d\n", window, gc, drawable, x1, y1, x2, y2, w, h);
gdk_draw_drawable (window, gc, drawable, x1, y1, x2, y2, w, h);
}
extern GtkWidget *mainwin;
extern GtkStatusIcon *trayicon;
extern gtkplaylist_t main_playlist;
// orange on dark color scheme
float colo_dark_orange[COLO_COUNT][3] = {
{ 0x7f/255.f, 0x7f/255.f, 0x7f/255.f }, // cursor
{ 0x1d/255.f, 0x1f/255.f, 0x1b/255.f }, // odd
{ 0x21/255.f, 0x23/255.f, 0x1f/255.f }, // even
{ 0xaf/255.f, 0xa7/255.f, 0x9e/255.f }, // sel odd
{ 0xa7/255.f, 0x9f/255.f, 0x96/255.f }, // sel even
{ 0xf4/255.f, 0x7e/255.f, 0x46/255.f }, // text
{ 0, 0, 0 }, // sel text
{ 0x1d/255.f, 0x1f/255.f, 0x1b/255.f }, // seekbar back
{ 0xf4/255.f, 0x7e/255.f, 0x46/255.f }, // seekbar front
{ 0x1d/255.f, 0x1f/255.f, 0x1b/255.f }, // volumebar back
{ 0xf4/255.f, 0x7e/255.f, 0x46/255.f }, // volumebar front
{ 0xf4/255.f, 0x7e/255.f, 0x46/255.f }, // dragdrop marker
};
float colo_white_blue[COLO_COUNT][3] = {
{ 0x7f/255.f, 0x7f/255.f, 0x7f/255.f }, // cursor
{ 1, 1, 1 }, // odd
{ 0xea/255.f, 0xeb/255.f, 0xec/255.f }, // even
{ 0x24/255.f, 0x89/255.f, 0xb8/255.f }, // sel odd
{ 0x20/255.f, 0x85/255.f, 0xb4/255.f }, // sel even
{ 0, 0, 0 }, // text
{ 1, 1, 1 }, // sel text
{ 0x1d/255.f, 0x1f/255.f, 0x1b/255.f }, // seekbar back
{ 0x24/255.f, 0x89/255.f, 0xb8/255.f }, // seekbar front
{ 0x1d/255.f, 0x1f/255.f, 0x1b/255.f }, // volumebar back
{ 0x24/255.f, 0x89/255.f, 0xb8/255.f }, // volumebar front
{ 0x09/255.f, 0x22/255.f, 0x3a/255.f }, // dragdrop marker
};
#define MIN_COLUMN_WIDTH 16
// current color scheme
float colo_current[COLO_COUNT][3];
// playlist row height
int rowheight = -1;
// playlist scrolling during dragging
static int playlist_scroll_mode = 0; // 0=select, 1=dragndrop
static int playlist_scroll_pointer_y = -1;
static int playlist_scroll_direction = 0;
static int playlist_scroll_active = 0;
static struct timeval tm_prevscroll;
static float scroll_sleep_time = 0;
static uintptr_t play16_pixbuf;
static uintptr_t pause16_pixbuf;
static uintptr_t buffering16_pixbuf;
static GdkCursor* cursor_sz;
static GdkCursor* cursor_drag;
static int header_dragging = -1;
static int header_sizing = -1;
static int header_dragpt[2];
#define COLHDR_ANIM_TIME 0.2f
#if 0
typedef struct {
int c1;
int c2;
int x1, x2;
int dx1, dx2;
// animated values
int ax1, ax2;
timeline_t *timeline;
int anim_active;
gtkplaylist_t *pl;
} colhdr_animator_t;
static colhdr_animator_t colhdr_anim;
static gboolean
redraw_header (void *data) {
colhdr_animator_t *anim = (colhdr_animator_t *)data;
gtkpl_header_draw (anim->pl);
gtkpl_expose_header (anim->pl, 0, 0, anim->pl->header->allocation.width, anim->pl->header->allocation.height);
return FALSE;
}
static int
colhdr_anim_cb (float _progress, int _last, void *_ctx) {
colhdr_animator_t *anim = (colhdr_animator_t *)_ctx;
anim->ax1 = anim->x1 + (float)(anim->dx1 - anim->x1) * _progress;
anim->ax2 = anim->x2 + (float)(anim->dx2 - anim->x2) * _progress;
// printf ("%f %d %d\n", _progress, anim->ax1, anim->ax2);
g_idle_add (redraw_header, anim);
if (_last) {
anim->anim_active = 0;
}
return 0;
}
static void
colhdr_anim_swap (gtkplaylist_t *pl, int c1, int c2, int x1, int x2) {
// interrupt previous anim
if (!colhdr_anim.timeline) {
colhdr_anim.timeline = timeline_create ();
}
colhdr_anim.pl = pl;
colhdr_anim.c1 = c1;
colhdr_anim.c2 = c2;
// find c1 and c2 in column list and setup coords
// note: columns are already swapped, so their coords must be reversed,
// as if before swap
gtkpl_column_t *c;
int idx = 0;
int x = 0;
for (c = pl->columns; c; c = c->next, idx++) {
if (idx == c1) {
colhdr_anim.x1 = x1;
colhdr_anim.dx2 = x;
}
else if (idx == c2) {
colhdr_anim.x2 = x2;
colhdr_anim.dx1 = x;
}
x += c->width;
}
colhdr_anim.anim_active = 1;
timeline_stop (colhdr_anim.timeline, 0);
timeline_init (colhdr_anim.timeline, COLHDR_ANIM_TIME, 100, colhdr_anim_cb, &colhdr_anim);
timeline_start (colhdr_anim.timeline);
}
#endif
// that must be called before gtk_init
void
gtkpl_init (void) {
//memcpy (colo_current, colo_system_gtk, sizeof (colo_current));
//memcpy (colo_current, colo_dark_orange, sizeof (colo_current));
play16_pixbuf = draw_load_pixbuf ("play_16.png");
pause16_pixbuf = draw_load_pixbuf ("pause_16.png");
buffering16_pixbuf = draw_load_pixbuf ("buffering_16.png");
rowheight = draw_get_font_size () + 12;
memcpy (colo_current, colo_white_blue, sizeof (colo_current));
}
void
gtkpl_free (gtkplaylist_t *pl) {
#if 0
if (colhdr_anim.timeline) {
timeline_free (colhdr_anim.timeline, 1);
colhdr_anim.timeline = 0;
}
#endif
while (pl->columns) {
gtkpl_column_t *next = pl->columns->next;
gtkpl_column_free (pl->columns);
pl->columns = next;
}
}
void
theme_set_cairo_source_rgb (cairo_t *cr, int col) {
cairo_set_source_rgb (cr, colo_current[col][0], colo_current[col][1], colo_current[col][2]);
}
void
theme_set_fg_color (int col) {
draw_set_fg_color (colo_current[col]);
}
void
theme_set_bg_color (int col) {
draw_set_bg_color (colo_current[col]);
}
void
gtkpl_setup_scrollbar (gtkplaylist_t *ps) {
GtkWidget *playlist = ps->playlist;
int h = playlist->allocation.height / rowheight;
int cnt = ps->get_count ();
int size = cnt;
if (h >= size) {
size = 0;
}
GtkWidget *scroll = ps->scrollbar;
int row = deadbeef->pl_get_cursor (ps->iterator);
if (row >= cnt) {
row = cnt - 1;
}
if (ps->scrollpos > cnt-ps->nvisiblerows+1) {
int n = cnt - ps->nvisiblerows + 1;
ps->scrollpos = max (0, n);
gtk_range_set_value (GTK_RANGE (scroll), ps->scrollpos);
}
if (size == 0) {
gtk_widget_hide (scroll);
}
else {
GtkAdjustment *adj = (GtkAdjustment*)gtk_adjustment_new (gtk_range_get_value (GTK_RANGE (scroll)), 0, size, 1, h, h);
gtk_range_set_adjustment (GTK_RANGE (scroll), adj);
gtk_widget_show (scroll);
}
}
void
gtkpl_setup_hscrollbar (gtkplaylist_t *ps) {
GtkWidget *playlist = ps->playlist;
int w = playlist->allocation.width;
int size = 0;
int i;
gtkpl_column_t *c;
for (c = ps->columns; c; c = c->next) {
size += c->width;
}
if (w >= size) {
size = 0;
}
GtkWidget *scroll = ps->hscrollbar;
if (ps->hscrollpos >= size-w) {
int n = size-w-1;
ps->hscrollpos = max (0, n);
gtk_range_set_value (GTK_RANGE (scroll), ps->hscrollpos);
}
if (size == 0) {
gtk_widget_hide (scroll);
}
else {
GtkAdjustment *adj = (GtkAdjustment*)gtk_adjustment_new (gtk_range_get_value (GTK_RANGE (scroll)), 0, size, 1, w, w);
gtk_range_set_adjustment (GTK_RANGE (scroll), adj);
gtk_widget_show (scroll);
}
}
void
gtkpl_redraw_pl_row_novis (gtkplaylist_t *ps, int row, DB_playItem_t *it) {
draw_begin ((uintptr_t)ps->backbuf);
gtkpl_draw_pl_row_back (ps, row, it);
if (it) {
gtkpl_draw_pl_row (ps, row, it);
}
draw_end ();
}
void
gtkpl_redraw_pl_row (gtkplaylist_t *ps, int row, DB_playItem_t *it) {
if (row < ps->scrollpos || row >= ps->scrollpos+ps->nvisiblerows) {
return;
}
int x, y, w, h;
GtkWidget *widget = ps->playlist;
x = 0;
y = (row - ps->scrollpos) * rowheight;
w = widget->allocation.width;
h = rowheight;
gtkpl_redraw_pl_row_novis (ps, row, it);
draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, x, y, x, y, w, h);
}
void
gtkpl_draw_pl_row_back (gtkplaylist_t *ps, int row, DB_playItem_t *it) {
// draw background
float w;
int start, end;
int startx, endx;
int width, height;
draw_get_canvas_size ((uintptr_t)ps->backbuf, &width, &height);
w = width;
if (it && SELECTED (it)) {
if (row % 2) {
theme_set_fg_color (COLO_PLAYLIST_SEL_EVEN);
}
else {
theme_set_fg_color (COLO_PLAYLIST_SEL_ODD);
}
draw_rect (0, row * rowheight - ps->scrollpos * rowheight, width, rowheight, 1);
}
else {
if (row % 2) {
theme_set_fg_color (COLO_PLAYLIST_EVEN);
}
else {
theme_set_fg_color (COLO_PLAYLIST_ODD);
}
draw_rect (0, row * rowheight - ps->scrollpos * rowheight, width, rowheight, 1);
}
if (row == deadbeef->pl_get_cursor (ps->iterator)) {
theme_set_fg_color (COLO_PLAYLIST_CURSOR);
draw_rect (0, row * rowheight - ps->scrollpos * rowheight, width, rowheight-1, 0);
}
}
void
gtkpl_draw_pl_row (gtkplaylist_t *ps, int row, DB_playItem_t *it) {
if (row-ps->scrollpos >= ps->nvisiblerows || row-ps->scrollpos < 0) {
// fprintf (stderr, "WARNING: attempt to draw row outside of screen bounds (%d)\n", row-ps->scrollpos);
return;
}
int width, height;
draw_get_canvas_size ((uintptr_t)ps->backbuf, &width, &height);
if (it && SELECTED (it)) {
if (row % 2) {
theme_set_bg_color (COLO_PLAYLIST_SEL_EVEN);
}
else {
theme_set_bg_color (COLO_PLAYLIST_SEL_ODD);
}
theme_set_fg_color (COLO_PLAYLIST_SEL_TEXT);
}
else {
if (row % 2) {
theme_set_bg_color (COLO_PLAYLIST_EVEN);
}
else {
theme_set_bg_color (COLO_PLAYLIST_ODD);
}
theme_set_fg_color (COLO_PLAYLIST_TEXT);
}
int x = -ps->hscrollpos;
gtkpl_column_t *c;
for (c = ps->columns; c; c = c->next) {
if (it == deadbeef->pl_getcurrent () && c->id == DB_COLUMN_PLAYING/* && !p_isstopped ()*/) {
int paused = deadbeef->playback_ispaused ();
int buffering = !deadbeef->streamer_ok_to_read (-1);
uintptr_t pixbuf;
if (paused) {
pixbuf = pause16_pixbuf;
}
else if (!buffering) {
pixbuf = play16_pixbuf;
}
else {
pixbuf = buffering16_pixbuf;
}
draw_pixbuf ((uintptr_t)ps->backbuf, pixbuf, x + c->width/2 - 8 - ps->hscrollpos, (row - ps->scrollpos) * rowheight + rowheight/2 - 8, 0, 0, 16, 16);
}
else {
char text[1024];
deadbeef->pl_format_title (it, text, sizeof (text), c->id, c->format);
if (text) {
if (c->align_right) {
draw_text_with_colors (x+5, row * rowheight - ps->scrollpos * rowheight + rowheight/2 - draw_get_font_size ()/2 - 2, c->width-10, 1, text);
}
else {
draw_text_with_colors (x + 5, row * rowheight - ps->scrollpos * rowheight + rowheight/2 - draw_get_font_size ()/2 - 2, c->width-10, 0, text);
}
}
}
x += c->width;
}
}
void
gtkpl_draw_playlist (gtkplaylist_t *ps, int x, int y, int w, int h) {
GtkWidget *widget = ps->playlist;
if (!ps->backbuf) {
return;
}
draw_begin ((uintptr_t)ps->backbuf);
int row;
int row1;
int row2;
int row2_full;
row1 = max (0, y / rowheight + ps->scrollpos);
int cnt = ps->get_count ();
row2 = min (cnt, (y+h) / rowheight + ps->scrollpos + 1);
row2_full = (y+h) / rowheight + ps->scrollpos + 1;
// draw background
DB_playItem_t *it = deadbeef->pl_get_for_idx_and_iter (ps->scrollpos, ps->iterator);
DB_playItem_t *it_copy = it;
for (row = row1; row < row2_full; row++) {
gtkpl_draw_pl_row_back (ps, row, it);
if (it) {
it = PL_NEXT (it, ps->iterator);
}
}
it = it_copy;
int idx = 0;
for (row = row1; row < row2; row++, idx++) {
gtkpl_draw_pl_row (ps, row, it);
it = PL_NEXT (it, ps->iterator);
}
draw_end ();
}
void
gtkpl_configure (gtkplaylist_t *ps) {
gtkpl_setup_scrollbar (ps);
gtkpl_setup_hscrollbar (ps);
GtkWidget *widget = ps->playlist;
if (ps->backbuf) {
g_object_unref (ps->backbuf);
ps->backbuf = NULL;
}
ps->nvisiblerows = ceil (widget->allocation.height / (float)rowheight);
ps->nvisiblefullrows = floor (widget->allocation.height / (float)rowheight);
ps->backbuf = gdk_pixmap_new (widget->window, widget->allocation.width, widget->allocation.height, -1);
gtkpl_draw_playlist (ps, 0, 0, widget->allocation.width, widget->allocation.height);
}
// change properties
gboolean
on_playlist_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
gpointer user_data)
{
// extern void main_playlist_init (GtkWidget *widget);
// main_playlist_init (widget);
GTKPL_PROLOGUE;
gtkpl_configure (ps);
return FALSE;
}
void
gtkpl_expose (gtkplaylist_t *ps, int x, int y, int w, int h) {
GtkWidget *widget = ps->playlist;
if (widget->window) {
draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, x, y, x, y, w, h);
}
}
void
gtkpl_expose_header (gtkplaylist_t *ps, int x, int y, int w, int h) {
GtkWidget *widget = ps->header;
draw_drawable (widget->window, widget->style->black_gc, ps->backbuf_header, x, y, x, y, w, h);
}
void
gtkpl_select_single (gtkplaylist_t *ps, int sel) {
int idx=0;
GtkWidget *widget = ps->playlist;
DB_playItem_t *it = PL_HEAD (ps->iterator);
for (; it; it = PL_NEXT (it, ps->iterator), idx++) {
if (idx == sel) {
if (!SELECTED (it)) {
VSELECT (it, 1);
}
}
else if (SELECTED (it)) {
VSELECT (it, 0);
}
}
}
// {{{ expected behaviour for mouse1 without modifiers:
// {{{ [+] if clicked unselected item:
// unselect all
// select clicked item
// deadbeef->pl_get_cursor (ps->iterator) = clicked
// redraw
// start 'area selection' mode
// }}}
// {{{ [+] if clicked selected item:
// deadbeef->pl_get_cursor (ps->iterator) = clicked
// redraw
// wait until next release or motion event, whichever is 1st
// if release is 1st:
// unselect all except clicked, redraw
// else if motion is 1st:
// enter drag-drop mode
// }}}
// }}}
static int areaselect = 0;
static int areaselect_x = -1;
static int areaselect_y = -1;
static int areaselect_dx = -1;
static int areaselect_dy = -1;
static int dragwait = 0;
static int shift_sel_anchor = -1;
void
gtkpl_mouse1_pressed (gtkplaylist_t *ps, int state, int ex, int ey, double time) {
// cursor must be set here, but selection must be handled in keyrelease
int cnt = ps->get_count ();
if (cnt == 0) {
return;
}
GtkWidget *widget = ps->playlist;
// remember mouse coords for doubleclick detection
ps->lastpos[0] = ex;
ps->lastpos[1] = ey;
// select item
int y = ey/rowheight + ps->scrollpos;
if (y < 0 || y >= ps->get_count ()) {
y = -1;
}
if (time - ps->clicktime < 0.5
&& fabs(ps->lastpos[0] - ex) < 3
&& fabs(ps->lastpos[1] - ey) < 3) {
// doubleclick - play this item
if (deadbeef->pl_get_cursor (ps->iterator) != -1) {
DB_playItem_t *it = deadbeef->pl_get_for_idx_and_iter (deadbeef->pl_get_cursor (ps->iterator), ps->iterator);
// SELECT (it, 1);
int r = deadbeef->pl_get_idx_of (it);
int prev = deadbeef->pl_get_cursor (ps->iterator);
if (prev != r) {
deadbeef->pl_set_cursor (ps->iterator, r);
if (prev != -1) {
gtkpl_redraw_pl_row (&main_playlist, prev, deadbeef->pl_get_for_idx (prev));
}
if (r != -1) {
gtkpl_redraw_pl_row (&main_playlist, r, it);
}
}
deadbeef->sendmessage (M_PLAYSONGNUM, 0, r, 0);
return;
}
// prevent next click to trigger doubleclick
ps->clicktime = time-1;
}
else {
ps->clicktime = time;
}
int sel = y;
if (y == -1) {
y = ps->get_count () - 1;
}
int prev = deadbeef->pl_get_cursor (ps->iterator);
deadbeef->pl_set_cursor (ps->iterator, y);
shift_sel_anchor = deadbeef->pl_get_cursor (ps->iterator);
// handle multiple selection
if (!(state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK)))
{
DB_playItem_t *it = deadbeef->pl_get_for_idx_and_iter (sel, ps->iterator);
if (!it || !SELECTED (it)) {
// reset selection, and set it to single item
gtkpl_select_single (ps, sel);
areaselect = 1;
areaselect_x = ex;
areaselect_y = ey;
areaselect_dx = -1;
areaselect_dy = -1;
shift_sel_anchor = deadbeef->pl_get_cursor (ps->iterator);
}
else {
dragwait = 1;
gtkpl_redraw_pl_row (ps, prev, gtkpl_get_for_idx (ps, prev));
if (deadbeef->pl_get_cursor (ps->iterator) != prev) {
gtkpl_redraw_pl_row (ps, deadbeef->pl_get_cursor (ps->iterator), gtkpl_get_for_idx (ps, deadbeef->pl_get_cursor (ps->iterator)));
}
}
}
else if (state & GDK_CONTROL_MASK) {
// toggle selection
if (y != -1) {
DB_playItem_t *it = gtkpl_get_for_idx (ps, y);
if (it) {
VSELECT (it, 1 - SELECTED (it));
}
}
}
else if (state & GDK_SHIFT_MASK) {
// select range
int start = min (prev, deadbeef->pl_get_cursor (ps->iterator));
int end = max (prev, deadbeef->pl_get_cursor (ps->iterator));
int idx = 0;
for (DB_playItem_t *it = PL_HEAD (ps->iterator); it; it = PL_NEXT (it, ps->iterator), idx++) {
if (idx >= start && idx <= end) {
if (!SELECTED (it)) {
VSELECT (it, 1);
}
}
else {
if (SELECTED (it)) {
VSELECT (it, 0);
}
}
}
}
if (deadbeef->pl_get_cursor (ps->iterator) != -1 && sel == -1) {
gtkpl_redraw_pl_row (ps, deadbeef->pl_get_cursor (ps->iterator), gtkpl_get_for_idx (ps, deadbeef->pl_get_cursor (ps->iterator)));
}
if (prev != -1 && prev != deadbeef->pl_get_cursor (ps->iterator)) {
gtkpl_redraw_pl_row (ps, prev, gtkpl_get_for_idx (ps, prev));
}
}
void
gtkpl_mouse1_released (gtkplaylist_t *ps, int state, int ex, int ey, double time) {
if (dragwait) {
dragwait = 0;
int y = ey/rowheight + ps->scrollpos;
gtkpl_select_single (ps, y);
}
else if (areaselect) {
playlist_scroll_direction = 0;
playlist_scroll_pointer_y = -1;
areaselect = 0;
}
}
#if 0
void
gtkpl_draw_areasel (GtkWidget *widget, int x, int y) {
// erase previous rect using 4 blits from ps->backbuffer
if (areaselect_dx != -1) {
int sx = min (areaselect_x, areaselect_dx);
int sy = min (areaselect_y, areaselect_dy);
int dx = max (areaselect_x, areaselect_dx);
int dy = max (areaselect_y, areaselect_dy);
int w = dx - sx + 1;
int h = dy - sy + 1;
//draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, sx, sy, sx, sy, dx - sx + 1, dy - sy + 1);
draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, sx, sy, sx, sy, w, 1);
draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, sx, sy, sx, sy, 1, h);
draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, sx, sy + h - 1, sx, sy + h - 1, w, 1);
draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, sx + w - 1, sy, sx + w - 1, sy, 1, h);
}
areaselect_dx = x;
areaselect_dy = y;
cairo_t *cr;
cr = gdk_cairo_create (widget->window);
if (!cr) {
return;
}
theme_set_fg_color (COLO_PLAYLIST_CURSOR);
cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
cairo_set_line_width (cr, 1);
int sx = min (areaselect_x, x);
int sy = min (areaselect_y, y);
int dx = max (areaselect_x, x);
int dy = max (areaselect_y, y);
cairo_rectangle (cr, sx, sy, dx-sx, dy-sy);
cairo_stroke (cr);
gtkpl_cairo_destroy (cr);
}
#endif
static gboolean
gtkpl_scroll_playlist_cb (gpointer data) {
gtkplaylist_t *ps = (gtkplaylist_t *)data;
playlist_scroll_active = 1;
struct timeval tm;
gettimeofday (&tm, NULL);
if (tm.tv_sec - tm_prevscroll.tv_sec + (tm.tv_usec - tm_prevscroll.tv_usec) / 1000000.0 < scroll_sleep_time) {
return TRUE;
}
memcpy (&tm_prevscroll, &tm, sizeof (tm));
if (playlist_scroll_pointer_y == -1) {
playlist_scroll_active = 0;
return FALSE;
}
if (playlist_scroll_direction == 0) {
playlist_scroll_active = 0;
return FALSE;
}
int sc = ps->scrollpos + playlist_scroll_direction;
if (sc < 0) {
playlist_scroll_active = 0;
return FALSE;
}
if (sc >= ps->get_count ()) {
playlist_scroll_active = 0;
return FALSE;
}
GDK_THREADS_ENTER ();
gtk_range_set_value (GTK_RANGE (ps->scrollbar), sc);
if (playlist_scroll_mode == 0) {
GdkEventMotion ev;
ev.y = playlist_scroll_pointer_y;
gtkpl_mousemove (ps, &ev);
}
else if (playlist_scroll_mode == 1) {
gtkpl_track_dragdrop (ps, playlist_scroll_pointer_y);
}
GDK_THREADS_LEAVE ();
scroll_sleep_time -= 0.1;
if (scroll_sleep_time < 0.05) {
scroll_sleep_time = 0.05;
}
return TRUE;
}
void
gtkpl_mousemove (gtkplaylist_t *ps, GdkEventMotion *event) {
if (dragwait) {
GtkWidget *widget = ps->playlist;
if (gtk_drag_check_threshold (widget, ps->lastpos[0], event->x, ps->lastpos[1], event->y)) {
dragwait = 0;
GtkTargetEntry entry = {
.target = "STRING",
.flags = GTK_TARGET_SAME_WIDGET,
.info = TARGET_SAMEWIDGET
};
GtkTargetList *lst = gtk_target_list_new (&entry, 1);
gtk_drag_begin (widget, lst, GDK_ACTION_MOVE, TARGET_SAMEWIDGET, (GdkEvent *)event);
}
}
else if (areaselect) {
GtkWidget *widget = ps->playlist;
int y = event->y/rowheight + ps->scrollpos;
//if (y != shift_sel_anchor)
{
int start = min (y, shift_sel_anchor);
int end = max (y, shift_sel_anchor);
int idx=0;
for (DB_playItem_t *it = PL_HEAD(ps->iterator); it; it = PL_NEXT(it, ps->iterator), idx++) {
if (idx >= start && idx <= end) {
if (!SELECTED (it)) {
VSELECT (it, 1);
}
}
else if (SELECTED (it)) {
VSELECT (it, 0);
}
}
}
if (event->y < 10) {
playlist_scroll_mode = 0;
playlist_scroll_pointer_y = event->y;
playlist_scroll_direction = -1;
// start scrolling up
if (!playlist_scroll_active) {
scroll_sleep_time = 0.2;
gettimeofday (&tm_prevscroll, NULL);
g_idle_add (gtkpl_scroll_playlist_cb, ps);
}
}
else if (event->y > ps->playlist->allocation.height-10) {
playlist_scroll_mode = 0;
playlist_scroll_pointer_y = event->y;
playlist_scroll_direction = 1;
// start scrolling up
if (!playlist_scroll_active) {
scroll_sleep_time = 0.2;
gettimeofday (&tm_prevscroll, NULL);
g_idle_add (gtkpl_scroll_playlist_cb, ps);
}
}
else {
playlist_scroll_direction = 0;
playlist_scroll_pointer_y = -1;
}
// debug only
// gtkpl_draw_areasel (widget, event->x, event->y);
}
}
void
gtkpl_handle_scroll_event (gtkplaylist_t *ps, int direction) {
GtkWidget *range = ps->scrollbar;;
GtkWidget *playlist = ps->playlist;
int h = playlist->allocation.height / rowheight;
int size = ps->get_count ();
if (h >= size) {
size = 0;
}
if (size == 0) {
return;
}
// pass event to scrollbar
GtkAdjustment* adj = gtk_range_get_adjustment (GTK_RANGE (range));
int newscroll = gtk_range_get_value (GTK_RANGE (range));
if (direction == GDK_SCROLL_UP) {
newscroll -= 2;
}
else if (direction == GDK_SCROLL_DOWN) {
newscroll += 2;
}
gtk_range_set_value (GTK_RANGE (range), newscroll);
}
void
gtkpl_scroll (gtkplaylist_t *ps, int newscroll) {
if (newscroll != ps->scrollpos) {
GtkWidget *widget = ps->playlist;
int di = newscroll - ps->scrollpos;
int d = abs (di);
if (d < ps->nvisiblerows) {
if (di > 0) {
draw_drawable (ps->backbuf, widget->style->black_gc, ps->backbuf, 0, d * rowheight, 0, 0, widget->allocation.width, widget->allocation.height-d * rowheight);
int i;
ps->scrollpos = newscroll;
int start = ps->nvisiblerows-d-1;
start = max (0, ps->nvisiblerows-d-1);
for (i = start; i <= ps->nvisiblerows; i++) {
gtkpl_redraw_pl_row_novis (ps, i+ps->scrollpos, gtkpl_get_for_idx (ps, i+ps->scrollpos));
}
}
else {
draw_drawable (ps->backbuf, widget->style->black_gc, ps->backbuf, 0, 0, 0, d*rowheight, widget->allocation.width, widget->allocation.height);
ps->scrollpos = newscroll;
int i;
for (i = 0; i <= d+1; i++) {
gtkpl_redraw_pl_row_novis (ps, i+ps->scrollpos, gtkpl_get_for_idx (ps, i+ps->scrollpos));
}
}
}
else {
ps->scrollpos = newscroll;
gtkpl_draw_playlist (ps, 0, 0, widget->allocation.width, widget->allocation.height);
}
draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, 0, 0, 0, 0, widget->allocation.width, widget->allocation.height);
}
}
void
gtkpl_hscroll (gtkplaylist_t *ps, int newscroll) {
if (newscroll != ps->hscrollpos) {
ps->hscrollpos = newscroll;
GtkWidget *widget = ps->playlist;
gtkpl_header_draw (ps);
gtkpl_expose_header (ps, 0, 0, ps->header->allocation.width, ps->header->allocation.height);
gtkpl_draw_playlist (ps, 0, 0, widget->allocation.width, widget->allocation.height);
draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, 0, 0, 0, 0, widget->allocation.width, widget->allocation.height);
}
}
void
gtkpl_songchanged (gtkplaylist_t *ps, int from, int to) {
if (!dragwait && to != -1) {
GtkWidget *widget = ps->playlist;
if (deadbeef->conf_get_int ("playlist.scroll.followplayback", 0)) {
if (to < ps->scrollpos || to >= ps->scrollpos + ps->nvisiblefullrows) {
gtk_range_set_value (GTK_RANGE (ps->scrollbar), to - ps->nvisiblerows/2);
}
}
}
if (from >= 0) {
gtkpl_redraw_pl_row (ps, from, gtkpl_get_for_idx (ps, from));
}
if (to >= 0) {
gtkpl_redraw_pl_row (ps, to, gtkpl_get_for_idx (ps, to));
}
}
void
gtkpl_keypress (gtkplaylist_t *ps, int keyval, int state) {
GtkWidget *widget = ps->playlist;
GtkWidget *range = ps->scrollbar;
int prev = deadbeef->pl_get_cursor (ps->iterator);
int newscroll = ps->scrollpos;
// C-f is now handled by gtk
// if ((keyval == GDK_F || keyval == GDK_f) && (state & GDK_CONTROL_MASK)) {
// search_start ();
// }
// else
// if ((keyval == GDK_A || keyval == GDK_a) && (state & GDK_CONTROL_MASK)) {
// // select all
// pl_select_all ();
// gtkpl_draw_playlist (ps, 0, 0, widget->allocation.width, widget->allocation.height);
// draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, 0, 0, 0, 0, widget->allocation.width, widget->allocation.height);
// return;
// }
// else if ((keyval == GDK_P || keyval == GDK_p) && (state & GDK_CONTROL_MASK)) {
// deadbeef->sendmessage (M_PAUSESONG, 0, 0, 0);
// }
// else
// if (keyval == GDK_Return && deadbeef->pl_get_cursor (ps->iterator) != -1) {
// deadbeef->sendmessage (M_PLAYSONGNUM, 0, deadbeef->pl_get_cursor (ps->iterator), 0);
// return;
// }
// else
// if (keyval == GDK_Delete) {
// pl_delete_selected ();
// playlist_refresh ();
// return;
// }
// else
if (keyval == GDK_Down && deadbeef->pl_get_cursor (ps->iterator) < ps->get_count () - 1) {
deadbeef->pl_set_cursor (ps->iterator, deadbeef->pl_get_cursor (ps->iterator) + 1);
if (deadbeef->pl_get_cursor (ps->iterator) > ps->scrollpos + widget->allocation.height / rowheight - 1) {
newscroll = deadbeef->pl_get_cursor (ps->iterator) - widget->allocation.height / rowheight + 1;
}
}
#if 0
else if (keyval == GDK_r) {
extern int replaygain;
replaygain = 1-replaygain;
fprintf (stderr, "replaygain=%d\n", replaygain);
}
else if (keyval == GDK_t) {
extern int replaygain_scale;
replaygain_scale = 1-replaygain_scale;
fprintf (stderr, "replaygain_scale=%d\n", replaygain_scale);
}
#endif
else if (keyval == GDK_Up && deadbeef->pl_get_cursor (ps->iterator) > 0) {
deadbeef->pl_set_cursor (ps->iterator, deadbeef->pl_get_cursor (ps->iterator) - 1);
if (deadbeef->pl_get_cursor (ps->iterator) < ps->scrollpos) {
newscroll = deadbeef->pl_get_cursor (ps->iterator);
}
}
else if (keyval == GDK_Page_Down && deadbeef->pl_get_cursor (ps->iterator) < ps->get_count () - 1) {
deadbeef->pl_set_cursor (ps->iterator, deadbeef->pl_get_cursor (ps->iterator) + 10);
if (deadbeef->pl_get_cursor (ps->iterator) >= ps->get_count ()) {
deadbeef->pl_set_cursor (ps->iterator, ps->get_count () - 1);
}
if (deadbeef->pl_get_cursor (ps->iterator) > ps->scrollpos + widget->allocation.height / rowheight - 1) {
newscroll = deadbeef->pl_get_cursor (ps->iterator) - widget->allocation.height / rowheight + 1;
}
}
else if (keyval == GDK_Page_Up && deadbeef->pl_get_cursor (ps->iterator) > 0) {
deadbeef->pl_set_cursor (ps->iterator, deadbeef->pl_get_cursor (ps->iterator) - 10);
if (deadbeef->pl_get_cursor (ps->iterator) < 0) {
deadbeef->pl_set_cursor (ps->iterator, 0);
}
if (deadbeef->pl_get_cursor (ps->iterator) < ps->scrollpos) {
newscroll = deadbeef->pl_get_cursor (ps->iterator);
}
}
else if (keyval == GDK_End && deadbeef->pl_get_cursor (ps->iterator) != ps->get_count () - 1) {
deadbeef->pl_set_cursor (ps->iterator, ps->get_count () - 1);
if (deadbeef->pl_get_cursor (ps->iterator) > ps->scrollpos + widget->allocation.height / rowheight - 1) {
newscroll = deadbeef->pl_get_cursor (ps->iterator) - widget->allocation.height / rowheight + 1;
}
}
else if (keyval == GDK_Home && deadbeef->pl_get_cursor (ps->iterator) != 0) {
deadbeef->pl_set_cursor (ps->iterator, 0);
if (deadbeef->pl_get_cursor (ps->iterator) < ps->scrollpos) {
newscroll = deadbeef->pl_get_cursor (ps->iterator);
}
}
if (state & GDK_SHIFT_MASK) {
// select all between shift_sel_anchor and deadbeef->pl_get_cursor (ps->iterator)
if (prev != deadbeef->pl_get_cursor (ps->iterator)) {
int minvis = ps->scrollpos;
int maxvis = ps->scrollpos + ps->nvisiblerows-1;
int start = min (deadbeef->pl_get_cursor (ps->iterator), shift_sel_anchor);
int end = max (deadbeef->pl_get_cursor (ps->iterator), shift_sel_anchor);
int idx=0;
for (DB_playItem_t *it = PL_HEAD (ps->iterator); it; it = PL_NEXT(it,ps->iterator), idx++) {
if (idx >= start && idx <= end) {
VSELECT (it, 1);
}
else if (SELECTED (it))
{
VSELECT (it, 0);
}
}
}
}
else {
// reset selection, set new single cursor/selection
if (prev != deadbeef->pl_get_cursor (ps->iterator)) {
int minvis = ps->scrollpos;
int maxvis = ps->scrollpos + ps->nvisiblerows-1;
shift_sel_anchor = deadbeef->pl_get_cursor (ps->iterator);
int idx=0;
for (DB_playItem_t *it = PL_HEAD (ps->iterator); it; it = PL_NEXT(it, ps->iterator), idx++) {
if (idx == deadbeef->pl_get_cursor (ps->iterator)) {
if (!SELECTED (it)) {
VSELECT (it, 1);
}
}
else if (SELECTED (it)) {
VSELECT (it, 0);
}
}
}
}
if (newscroll != ps->scrollpos) {
gtk_range_set_value (GTK_RANGE (range), newscroll);
}
}
static int drag_motion_y = -1;
void
gtkpl_track_dragdrop (gtkplaylist_t *ps, int y) {
GtkWidget *widget = ps->playlist;
if (drag_motion_y != -1) {
// erase previous track
draw_drawable (widget->window, widget->style->black_gc, ps->backbuf, 0, drag_motion_y * rowheight-3, 0, drag_motion_y * rowheight-3, widget->allocation.width, 7);
}
if (y == -1) {
drag_motion_y = -1;
return;
}
draw_begin ((uintptr_t)widget->window);
drag_motion_y = y / rowheight;
theme_set_fg_color (COLO_DRAGDROP_MARKER);
draw_rect (0, drag_motion_y * rowheight-1, widget->allocation.width, 3, 1);
draw_rect (0, drag_motion_y * rowheight-3, 3, 7, 1);
draw_rect (widget->allocation.width-3, drag_motion_y * rowheight-3, 3, 7, 1);
draw_end ();
if (y < 10) {
playlist_scroll_pointer_y = y;
playlist_scroll_direction = -1;
playlist_scroll_mode = 1;
// start scrolling up
if (!playlist_scroll_active) {
scroll_sleep_time = 0.2;
gettimeofday (&tm_prevscroll, NULL);
g_idle_add (gtkpl_scroll_playlist_cb, ps);
}
}
else if (y > ps->playlist->allocation.height-10) {
playlist_scroll_mode = 1;
playlist_scroll_pointer_y = y;
playlist_scroll_direction = 1;
// start scrolling up
if (!playlist_scroll_active) {
scroll_sleep_time = 0.2;
gettimeofday (&tm_prevscroll, NULL);
g_idle_add (gtkpl_scroll_playlist_cb, ps);
}
}
else {
playlist_scroll_direction = 0;
playlist_scroll_pointer_y = -1;
}
}
void
on_playlist_drag_end (GtkWidget *widget,
GdkDragContext *drag_context,
gpointer user_data)
{
GTKPL_PROLOGUE;
// invalidate entire cache - slow, but rare
gtkpl_draw_playlist (ps, 0, 0, widget->allocation.width, widget->allocation.height);
gtkpl_expose (ps, 0, 0, widget->allocation.width, widget->allocation.height);
playlist_scroll_direction = 0;
playlist_scroll_pointer_y = -1;
}
void
strcopy_special (char *dest, const char *src, int len) {
while (len > 0) {
if (*src == '%' && len >= 3) {
int charcode = 0;
int byte;
byte = tolower (src[2]);
if (byte >= '0' && byte <= '9') {
charcode = byte - '0';
}
else if (byte >= 'a' && byte <= 'f') {
charcode = byte - 'a' + 10;
}
else {
charcode = '?';
}
if (charcode != '?') {
byte = tolower (src[1]);
if (byte >= '0' && byte <= '9') {
charcode |= (byte - '0') << 4;
}
else if (byte >= 'a' && byte <= 'f') {
charcode |= (byte - 'a' + 10) << 4;
}
else {
charcode = '?';
}
}
*dest = charcode;
dest++;
src += 3;
len -= 3;
continue;
}
else {
*dest++ = *src++;
len--;
}
}
*dest = 0;
}
int
gtkpl_add_file_info_cb (DB_playItem_t *it, void *data) {
if (progress_is_aborted ()) {
return -1;
}
GDK_THREADS_ENTER();
progress_settext (it->fname);
GDK_THREADS_LEAVE();
return 0;
}
void
gtkpl_add_fm_dropped_files (gtkplaylist_t *ps, char *ptr, int length, int drop_y) {
GDK_THREADS_ENTER();
progress_show ();
GDK_THREADS_LEAVE();
int drop_row = drop_y / rowheight + ps->scrollpos;
DB_playItem_t *drop_before = deadbeef->pl_get_for_idx_and_iter (drop_row, ps->iterator);
DB_playItem_t *after = NULL;
if (drop_before) {
after = PL_PREV (drop_before, ps->iterator);
}
else {
after = PL_TAIL (ps->iterator);
}
const uint8_t *p = (const uint8_t*)ptr;
while (*p) {
const uint8_t *pe = p;
while (*pe && *pe > ' ') {
pe++;
}
if (pe - p < 4096 && pe - p > 7) {
char fname[(int)(pe - p)];
strcopy_special (fname, p, pe-p);
//strncpy (fname, p, pe - p);
//fname[pe - p] = 0;
int abort = 0;
DB_playItem_t *inserted = deadbeef->pl_insert_dir (after, fname, &abort, gtkpl_add_file_info_cb, NULL);
if (!inserted && !abort) {
inserted = deadbeef->pl_insert_file (after, fname, &abort, gtkpl_add_file_info_cb, NULL);
}
if (inserted) {
after = inserted;
}
}
p = pe;
// skip whitespace
while (*p && *p <= ' ') {
p++;
}
}
free (ptr);
GDK_THREADS_ENTER();
progress_hide ();
playlist_refresh ();
GDK_THREADS_LEAVE();
}
void
gtkpl_header_draw (gtkplaylist_t *ps) {
GtkWidget *widget = ps->header;
int x = -ps->hscrollpos;
int w = 100;
int h = widget->allocation.height;
const char *detail = "button";
// fill background
gtk_paint_box (widget->style, ps->backbuf_header, GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, widget, detail, -10, -10, widget->allocation.width+20, widget->allocation.height+20);
gdk_draw_line (ps->backbuf_header, widget->style->mid_gc[GTK_STATE_NORMAL], 0, widget->allocation.height-1, widget->allocation.width, widget->allocation.height-1);
draw_begin ((uintptr_t)ps->backbuf_header);
x = -ps->hscrollpos;
gtkpl_column_t *c;
int need_draw_moving = 0;
int idx = 0;
for (c = ps->columns; c; c = c->next, idx++) {
w = c->width;
int xx = x;
#if 0
if (colhdr_anim.anim_active) {
if (idx == colhdr_anim.c2) {
xx = colhdr_anim.ax1;
}
else if (idx == colhdr_anim.c1) {
xx = colhdr_anim.ax2;
}
}
#endif
if (header_dragging < 0 || idx != header_dragging) {
if (xx >= widget->allocation.width) {
continue;
}
int arrow_sz = 10;
if (w > 0) {
gtk_paint_vline (widget->style, ps->backbuf_header, GTK_STATE_NORMAL, NULL, NULL, NULL, 2, h-4, xx+w - 2);
GdkColor *gdkfg = &widget->style->fg[0];
float fg[3] = {(float)gdkfg->red/0xffff, (float)gdkfg->green/0xffff, (float)gdkfg->blue/0xffff};
draw_set_fg_color (fg);
int w = c->width-10;
if (c->sort_order) {
w -= arrow_sz;
if (w < 0) {
w = 0;
}
}
draw_text (xx + 5, h/2-draw_get_font_size()/2, w, 0, c->title);
}
if (c->sort_order != 0) {
int dir = c->sort_order == 1 ? GTK_ARROW_DOWN : GTK_ARROW_UP;
gtk_paint_arrow (widget->style, ps->backbuf_header, GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, widget, NULL, dir, TRUE, xx + c->width-arrow_sz-5, widget->allocation.height/2-arrow_sz/2, arrow_sz, arrow_sz);
}
}
else {
need_draw_moving = 1;
}
x += w;
}
if (need_draw_moving) {
x = -ps->hscrollpos;
idx = 0;
for (c = ps->columns; c; c = c->next, idx++) {
w = c->width;
if (idx == header_dragging) {
#if 0
if (colhdr_anim.anim_active) {
if (idx == colhdr_anim.c2) {
x = colhdr_anim.ax1;
}
else if (idx == colhdr_anim.c1) {
x = colhdr_anim.ax2;
}
}
#endif
// draw empty slot
if (x < widget->allocation.width) {
gtk_paint_box (widget->style, ps->backbuf_header, GTK_STATE_ACTIVE, GTK_SHADOW_ETCHED_IN, NULL, widget, "button", x, 0, w, h);
}
x = c->movepos;
if (x >= widget->allocation.width) {
break;
}
if (w > 0) {
gtk_paint_box (widget->style, ps->backbuf_header, GTK_STATE_SELECTED, GTK_SHADOW_OUT, NULL, widget, "button", x, 0, w, h);
GdkColor *gdkfg = &widget->style->fg[GTK_STATE_SELECTED];
float fg[3] = {(float)gdkfg->red/0xffff, (float)gdkfg->green/0xffff, (float)gdkfg->blue/0xffff};
draw_set_fg_color (fg);
draw_text (x + 5, h/2-draw_get_font_size()/2, c->width-10, 0, c->title);
}
break;
}
x += w;
}
}
draw_end ();
}
gboolean
on_header_expose_event (GtkWidget *widget,
GdkEventExpose *event,
gpointer user_data)
{
GTKPL_PROLOGUE;
gtkpl_header_draw (ps);
gtkpl_expose_header (ps, event->area.x, event->area.y, event->area.width, event->area.height);
return FALSE;
}
gboolean
on_header_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
gpointer user_data)
{
GTKPL_PROLOGUE;
if (ps->backbuf_header) {
g_object_unref (ps->backbuf_header);
ps->backbuf_header = NULL;
}
ps->backbuf_header = gdk_pixmap_new (widget->window, widget->allocation.width, widget->allocation.height, -1);
gtkpl_header_draw (ps);
return FALSE;
}
void
on_header_realize (GtkWidget *widget,
gpointer user_data)
{
// create cursor for sizing headers
int h = draw_get_font_size ();
gtk_widget_set_size_request (widget, -1, h + 10);
cursor_sz = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
cursor_drag = gdk_cursor_new (GDK_FLEUR);
}
static float last_header_motion_ev = -1;
static int prev_header_x = -1;
static int header_prepare = 0;
gboolean
on_header_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event,
gpointer user_data)
{
GTKPL_PROLOGUE;
if ((event->state & GDK_BUTTON1_MASK) && header_prepare) {
if (gtk_drag_check_threshold (widget, event->x, prev_header_x, 0, 0)) {
header_prepare = 0;
}
}
if (!header_prepare && header_dragging >= 0) {
gdk_window_set_cursor (widget->window, cursor_drag);
gtkpl_column_t *c;
int i;
for (i = 0, c = ps->columns; i < header_dragging && c; c = c->next, i++);
c->movepos = event->x - header_dragpt[0];
// find closest column to the left
int inspos = -1;
gtkpl_column_t *cc;
int x = 0;
int idx = 0;
int x1 = -1, x2 = -1;
for (cc = ps->columns; cc; cc = cc->next, idx++) {
if (x < c->movepos && x + c->width > c->movepos) {
inspos = idx;
x1 = x;
}
else if (idx == header_dragging) {
x2 = x;
}
x += cc->width;
}
if (inspos >= 0 && inspos != header_dragging) {
int c1 = inspos;
int c2 = header_dragging;
// remove c from list
if (c == ps->columns) {
ps->columns = c->next;
}
else {
for (cc = ps->columns; cc; cc = cc->next) {
if (cc->next == c) {
cc->next = c->next;
}
}
}
c->next = NULL;
// reinsert c at position inspos update header_dragging to new idx
header_dragging = inspos;
if (inspos == 0) {
c->next = ps->columns;
ps->columns = c;
}
else {
idx = 0;
gtkpl_column_t *prev = NULL;
for (cc = ps->columns; cc; cc = cc->next, idx++, prev = cc) {
if (idx+1 == inspos) {
gtkpl_column_t *next = cc->next;
cc->next = c;
c->next = next;
break;
}
}
}
// colhdr_anim_swap (ps, c1, c2, x1, x2);
// force redraw of everything
// gtkpl_setup_hscrollbar (ps);
gtkpl_draw_playlist (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height);
gtkpl_expose (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height);
gtkpl_column_update_config (ps, c, i);
}
else {
// only redraw that if not animating
gtkpl_header_draw (ps);
gtkpl_expose_header (ps, 0, 0, ps->header->allocation.width, ps->header->allocation.height);
}
}
else if (header_sizing >= 0) {
last_header_motion_ev = event->time;
prev_header_x = event->x;
gdk_window_set_cursor (widget->window, cursor_sz);
// get column start pos
int x = -ps->hscrollpos;
int i = 0;
gtkpl_column_t *c;
for (c = ps->columns; c && i < header_sizing; c = c->next, i++) {
x += c->width;
}
int newx = event->x > x + MIN_COLUMN_WIDTH ? event->x : x + MIN_COLUMN_WIDTH;
c->width = newx - x;
gtkpl_setup_hscrollbar (ps);
gtkpl_header_draw (ps);
gtkpl_expose_header (ps, 0, 0, ps->header->allocation.width, ps->header->allocation.height);
gtkpl_draw_playlist (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height);
gtkpl_expose (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height);
gtkpl_column_update_config (ps, c, i);
}
else {
int x = -ps->hscrollpos;
gtkpl_column_t *c;
for (c = ps->columns; c; c = c->next) {
int w = c->width;
if (w > 0) { // ignore collapsed columns (hack for search window)
if (event->x >= x + w - 2 && event->x <= x + w) {
gdk_window_set_cursor (widget->window, cursor_sz);
break;
}
else {
gdk_window_set_cursor (widget->window, NULL);
}
}
else {
gdk_window_set_cursor (widget->window, NULL);
}
x += w;
}
}
return FALSE;
}
gboolean
on_header_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
GTKPL_PROLOGUE;
if (event->button == 1) {
// start sizing/dragging
header_dragging = -1;
header_sizing = -1;
header_dragpt[0] = event->x;
header_dragpt[1] = event->y;
int x = -ps->hscrollpos;
int i = 0;
gtkpl_column_t *c;
for (c = ps->columns; c; c = c->next, i++) {
int w = c->width;
if (event->x >= x + w - 2 && event->x <= x + w) {
header_sizing = i;
header_dragging = -1;
break;
}
else if (event->x > x + 2 && event->x < x + w - 2) {
// prepare to drag or sort
header_dragpt[0] = event->x - x;
header_prepare = 1;
header_dragging = i;
header_sizing = -1;
prev_header_x = event->x;
break;
}
x += w;
}
}
else if (event->button == 3) {
GtkWidget *menu = create_headermenu ();
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, widget, 0, gtk_get_current_event_time());
}
prev_header_x = -1;
last_header_motion_ev = -1;
return FALSE;
}
gboolean
on_header_button_release_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
GTKPL_PROLOGUE;
if (event->button == 1) {
if (header_prepare) {
header_sizing = -1;
header_dragging = -1;
header_prepare = 0;
// sort
gtkpl_column_t *c;
int i = 0;
int x = -ps->hscrollpos;
int sorted = 0;
for (c = ps->columns; c; c = c->next, i++) {
int w = c->width;
if (event->x > x + 2 && event->x < x + w - 2) {
if (!c->sort_order) {
c->sort_order = 1;
}
else if (c->sort_order == 1) {
c->sort_order = 2;
}
else if (c->sort_order == 2) {
c->sort_order = 1;
}
deadbeef->pl_sort (ps == &main_playlist ? PL_MAIN : PL_SEARCH, c->id, c->format, c->sort_order-1);
sorted = 1;
}
else {
c->sort_order = 0;
}
x += w;
}
playlist_refresh ();
gtkpl_header_draw (ps);
gtkpl_expose_header (ps, 0, 0, ps->header->allocation.width, ps->header->allocation.height);
}
else {
header_sizing = -1;
int x = 0;
gtkpl_column_t *c;
for (c = ps->columns; c; c = c->next) {
int w = c->width;
if (event->x >= x + w - 2 && event->x <= x + w) {
gdk_window_set_cursor (widget->window, cursor_sz);
break;
}
else {
gdk_window_set_cursor (widget->window, NULL);
}
x += w;
}
if (header_dragging >= 0) {
header_dragging = -1;
gtkpl_setup_hscrollbar (ps);
gtkpl_header_draw (ps);
gtkpl_expose_header (ps, 0, 0, ps->header->allocation.width, ps->header->allocation.height);
gtkpl_draw_playlist (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height);
gtkpl_expose (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height);
gtkpl_column_rewrite_config (ps);
}
}
}
return FALSE;
}
void
gtkpl_add_dir (gtkplaylist_t *ps, char *folder) {
GDK_THREADS_ENTER();
progress_show ();
GDK_THREADS_LEAVE();
deadbeef->pl_add_dir (folder, gtkpl_add_file_info_cb, NULL);
g_free (folder);
GDK_THREADS_ENTER();
progress_hide ();
playlist_refresh ();
GDK_THREADS_LEAVE();
}
static void
gtkpl_adddir_cb (gpointer data, gpointer userdata) {
deadbeef->pl_add_dir (data, gtkpl_add_file_info_cb, userdata);
g_free (data);
}
void
gtkpl_add_dirs (gtkplaylist_t *ps, GSList *lst) {
GDK_THREADS_ENTER();
progress_show ();
GDK_THREADS_LEAVE();
g_slist_foreach(lst, gtkpl_adddir_cb, NULL);
g_slist_free (lst);
GDK_THREADS_ENTER();
progress_hide ();
playlist_refresh ();
GDK_THREADS_LEAVE();
}
static void
gtkpl_addfile_cb (gpointer data, gpointer userdata) {
deadbeef->pl_add_file (data, gtkpl_add_file_info_cb, userdata);
g_free (data);
}
void
gtkpl_add_files (gtkplaylist_t *ps, GSList *lst) {
GDK_THREADS_ENTER();
progress_show ();
GDK_THREADS_LEAVE();
g_slist_foreach(lst, gtkpl_addfile_cb, NULL);
g_slist_free (lst);
GDK_THREADS_ENTER();
progress_hide ();
playlist_refresh ();
GDK_THREADS_LEAVE();
}
int
gtkpl_get_idx_of (gtkplaylist_t *ps, DB_playItem_t *it) {
DB_playItem_t *c = PL_HEAD(ps->iterator);
int idx = 0;
while (c && c != it) {
c = PL_NEXT(c, ps->iterator);;
idx++;
}
if (!c) {
return -1;
}
return idx;
}
DB_playItem_t *
gtkpl_get_for_idx (gtkplaylist_t *ps, int idx) {
DB_playItem_t *it = PL_HEAD(ps->iterator);
while (idx--) {
if (!it)
return NULL;
it = PL_NEXT(it, ps->iterator);
}
return it;
}
void
playlist_refresh (void) {
extern gtkplaylist_t main_playlist;
gtkplaylist_t *ps = &main_playlist;
gtkpl_setup_scrollbar (ps);
GtkWidget *widget = ps->playlist;
gtkpl_draw_playlist (ps, 0, 0, widget->allocation.width, widget->allocation.height);
gtkpl_expose (ps, 0, 0, widget->allocation.width, widget->allocation.height);
search_refresh ();
}
gtkpl_column_t *
gtkpl_column_alloc (const char *title, int width, int id, const char *format, int align_right) {
gtkpl_column_t *c = malloc (sizeof (gtkpl_column_t));
memset (c, 0, sizeof (gtkpl_column_t));
c->title = strdup (title);
c->id = id;
c->format = format ? strdup (format) : NULL;
c->width = width;
c->align_right = align_right;
return c;
}
void
gtkpl_column_append (gtkplaylist_t *pl, gtkpl_column_t *c) {
int idx = 0;
if (pl->columns) {
idx++;
gtkpl_column_t *tail = pl->columns;
while (tail->next) {
tail = tail->next;
idx++;
}
tail->next = c;
}
else {
pl->columns = c;
}
gtkpl_column_update_config (pl, c, idx);
}
void
gtkpl_column_free (gtkpl_column_t *c) {
if (c->title) {
free (c->title);
}
if (c->format) {
free (c->format);
}
free (c);
}
void
gtkpl_column_remove (gtkplaylist_t *pl, gtkpl_column_t *c) {
if (pl->columns == c) {
pl->columns = pl->columns->next;
gtkpl_column_free (c);
return;
}
gtkpl_column_t *cc = pl->columns;
while (cc) {
if (cc->next == c) {
cc->next = cc->next->next;
gtkpl_column_free (c);
return;
}
cc = cc->next;
}
assert (cc && "gtkpl: attempted to remove column that is not in list");
}
void
gtkpl_append_column_from_textdef (gtkplaylist_t *pl, const uint8_t *def) {
// syntax: "title" "format" id width alignright
char title[128];
char format[128];
int id;
int width;
int align_right;
// title
if (*def != '"') {
return;
}
def++;
if (*def == 0) {
return;
}
const uint8_t *e = def;
e++;
while (*e && *e != '"') {
e++;
}
if (*e == 0) {
return;
}
memcpy (title, def, e-def);
title[e-def] = 0;
// skip whitespace
def = e;
def++;
while (*def && *def <= ' ') {
def++;
}
if (*def == 0) {
return;
}
// format
if (*def != '"') {
return;
}
def++;
if (*def == 0) {
return;
}
e = def;
while (*e && *e != '"') {
e++;
}
if (*e == 0) {
return;
}
memcpy (format, def, e-def);
format[e-def] = 0;
// skip whitespace
def = e;
def++;
while (*def && *def <= ' ') {
def++;
}
if (*def == 0) {
return;
}
// id
e = def;
while (*e && (isdigit (*e) || *e == '-')) {
e++;
}
if (*e == 0) {
return;
}
{
char s[e-def+1];
memcpy (s, def, e-def);
s[e-def] = 0;
id = atoi (s);
}
// skip whitespace
def = e;
def++;
while (*def && *def <= ' ') {
def++;
}
if (*def == 0) {
return;
}
// width
e = def;
while (*e && isdigit (*e)) {
e++;
}
if (*e == 0) {
return;
}
{
char s[e-def+1];
memcpy (s, def, e-def);
s[e-def] = 0;
width = atoi (s);
}
// skip whitespace
def = e;
def++;
while (*def && *def <= ' ') {
def++;
}
if (*def == 0) {
return;
}
// align_right
e = def;
while (*e && isdigit (*e)) {
e++;
}
{
char s[e-def+1];
memcpy (s, def, e-def);
s[e-def] = 0;
align_right = atoi (s);
}
gtkpl_column_append (pl, gtkpl_column_alloc (title, width, id, format[0] ? format : NULL, align_right));
}
void
gtkpl_column_update_config (gtkplaylist_t *pl, gtkpl_column_t *c, int idx) {
char key[128];
char value[128];
snprintf (key, sizeof (key), "%s.column.%d", pl->title, idx);
snprintf (value, sizeof (value), "\"%s\" \"%s\" %d %d %d", c->title, c->format ? c->format : "", c->id, c->width, c->align_right);
deadbeef->conf_set_str (key, value);
}
void
gtkpl_column_rewrite_config (gtkplaylist_t *pl) {
char key[128];
char value[128];
snprintf (key, sizeof (key), "%s.column.", pl->title);
deadbeef->conf_remove_items (key);
gtkpl_column_t *c;
int i = 0;
for (c = pl->columns; c; c = c->next, i++) {
snprintf (key, sizeof (key), "%s.column.%d", pl->title, i);
snprintf (value, sizeof (value), "\"%s\" \"%s\" %d %d %d", c->title, c->format ? c->format : "", c->id, c->width, c->align_right);
deadbeef->conf_set_str (key, value);
}
}
void
set_tray_tooltip (const char *text) {
#if (GTK_MINOR_VERSION < 16)
gtk_status_icon_set_tooltip (trayicon, text);
#else
gtk_status_icon_set_tooltip_text (trayicon, text);
#endif
}
void
gtkpl_current_track_changed (DB_playItem_t *it) {
char str[600];
if (it) {
char dname[512];
deadbeef->pl_format_item_display_name (it, dname, 512);
snprintf (str, sizeof (str), "DeaDBeeF - %s", dname);
}
else {
strcpy (str, "DeaDBeeF");
}
gtk_window_set_title (GTK_WINDOW (mainwin), str);
set_tray_tooltip (str);
}
void
gtkpl_songchanged_wrapper (int from, int to) {
GDK_THREADS_ENTER ();
// update window title
if (from >= 0 || to >= 0) {
if (to >= 0) {
DB_playItem_t *it = deadbeef->pl_get_for_idx (to);
if (it) { // it might have been deleted after event was sent
gtkpl_current_track_changed (it);
}
}
else {
gtk_window_set_title (GTK_WINDOW (mainwin), "DeaDBeeF");
set_tray_tooltip ("DeaDBeeF");
}
}
// update playlist view
gtkpl_songchanged (&main_playlist, from, to);
GDK_THREADS_LEAVE ();
}
void
gtk_pl_redraw_item_everywhere (DB_playItem_t *it) {
gtkplaylist_t *pl = &search_playlist;
int idx = gtkpl_get_idx_of (pl, it);
int minvis = pl->scrollpos;
int maxvis = pl->scrollpos + pl->nvisiblerows-1;
if (idx >= minvis && idx <= maxvis) {
gtkpl_redraw_pl_row (pl, idx, it);
}
pl = &main_playlist;
idx = gtkpl_get_idx_of (pl, it);
minvis = pl->scrollpos;
maxvis = pl->scrollpos + pl->nvisiblerows-1;
if (idx >= minvis && idx <= maxvis) {
gtkpl_redraw_pl_row (pl, idx, it);
}
}
void
gtkpl_set_cursor (int iter, int cursor) {
gtkplaylist_t *pl = &main_playlist;
int minvis = pl->scrollpos;
int maxvis = pl->scrollpos + pl->nvisiblerows-1;
int prev = deadbeef->pl_get_cursor (PL_MAIN);
deadbeef->pl_set_cursor (PL_MAIN, 0);
DB_playItem_t *it;
if (prev >= minvis && prev <= maxvis) {
it = deadbeef->pl_get_for_idx_and_iter (prev, PL_MAIN);
gtkpl_redraw_pl_row (pl, prev, it);
}
if (0 >= minvis && 0 <= maxvis) {
it = deadbeef->pl_get_for_idx_and_iter (0, PL_MAIN);
gtkpl_redraw_pl_row (pl, 0, it);
}
}
|