This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhelpers.lua
849 lines (770 loc) · 28.6 KB
/
helpers.lua
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
local beautiful = require("beautiful")
local wibox = require("wibox")
local gears = require("gears")
local awful = require("awful")
local timer = require("gears.timer")
local dpi = beautiful.xresources.apply_dpi
local helpers = {}
function helpers.set_widget_block(args)
local widget = args.widget
local left = args.left or 0
local right = args.right or 0
local top = args.top or 0
local bottom = args.bottom or 0
local margin_left = args.margin_left or 0
local margin_right = args.margin_right or 0
local margin_top = args.margin_top or 0
local margin_bottom = args.margin_bottom or 0
local shape = args.shape or gears.shape.rectangle
local fg = args.fg or beautiful.fg_normal
local bg = args.bg or beautiful.widget_bg
local font = args.font or beautiful.iconfont
local visible = args.visible
local forced_height = args.forced_height
local forced_width = args.forced_width
local border_width = args.border_width
local border_color = args.border_color
local bgimage = args.bgimage or nil
local screen = args.screen
local id = args.id
local margin_id = args.margin_id
local block =
helpers.add_margin {
widget = {
{
widget,
left = left,
right = right,
top = top,
bottom = bottom,
widget = wibox.container.margin
},
shape = shape,
bgimage = bgimage,
fg = fg,
bg = bg,
visible = visible,
font = font,
id = id,
forced_height = forced_height,
forced_width = forced_width,
border_width = border_width,
border_color = border_color,
screen = screen,
widget = wibox.container.background
},
id = margin_id,
left = margin_left,
right = margin_right,
top = margin_top,
bottom = margin_bottom
}
return block
end
function helpers.add_text_icon_widget(args)
local text = args.text or ""
local text_font = args.text_font
local text_bg = args.text_bg
local icon = args.icon or ""
local icon_font = args.icon_font
local icon_bg = args.icon_bg
local icon_forced_width = args.icon_forced_width
local icon_position_x = args.icon_position_x or 0
local forced_width = args.forced_width
local forced_height = args.forced_height or dpi(50)
local ltr = args.ltr or false
local text_position = function(geo, args)
return {
x = args.parent.width - geo.width,
y = (args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end
local icon_position = function(geo, args)
return {
x = icon_position_x,
y = (args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end
if ltr then
text_position = function(geo, args)
return {
x = 0,
y = (args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end
icon_position = function(geo, args)
return {
x = args.parent.width - geo.width,
y = (args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end
end
local widget =
wibox.widget {
layout = wibox.layout.manual,
forced_height = forced_height,
forced_width = forced_width,
{
point = text_position,
{
text = text,
align = "center",
valign = "center",
id = "text_id",
font = text_font,
fg = text_bg,
widget = wibox.widget.textbox
},
id = "left",
layout = wibox.layout.fixed.vertical
},
{
point = icon_position,
id = "right",
{
text = icon,
align = "center",
valign = "center",
id = "icon_id",
font = icon_font,
bg = icon_bg,
forced_width = icon_forced_width,
widget = wibox.widget.textbox
},
-- helpers.add_text(icon, icon_bg, icon_font),
layout = wibox.layout.fixed.vertical
}
}
return widget
end
function helpers.right_rounded_rect(radius)
return function(cr, w, h)
gears.shape.partially_rounded_rect(cr, w, h, false, true, true, false, radius)
end
end
function helpers.left_rounded_rect(radius)
return function(cr, w, h)
gears.shape.partially_rounded_rect(cr, w, h, true, false, false, true, radius)
end
end
function helpers.set_space(space_size)
local space =
wibox.widget {
forced_width = space_size,
-- spacing = space_size,
spacing_widget = wibox.widget.separator,
layout = wibox.layout.flex.horizontal
}
return space
end
-- Create rounded rectangle shape (in one line)
function helpers.rrect(radius)
return function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, radius or beautiful.groups_radius)
end
end
function helpers.colorize_text(txt, fg, font)
if fg == nil then
fg = beautiful.fg_normal
end
if font == nil then
font = beautiful.iconfont
end
return "<span foreground='" .. fg .. "' font='" .. font .. "'>" .. txt .. "</span>"
end
function helpers.add_text(txt, bg, font, align, valign)
local in_valign = valign or "center"
local in_align = align or "center"
return wibox.widget {
markup = helpers.colorize_text(txt, bg, font),
align = in_align,
valign = in_valign,
id = "text_id",
widget = wibox.widget.textbox
}
end
function helpers.add_hover_cursor(w, hover_cursor)
local original_cursor = "left_ptr"
w:connect_signal(
"mouse::enter",
function()
local w = _G.mouse.current_wibox
if w then
w.cursor = hover_cursor
end
end
)
w:connect_signal(
"mouse::leave",
function()
local w = _G.mouse.current_wibox
if w then
w.cursor = original_cursor
end
end
)
end
helpers.rrect = function(radius)
return function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, radius)
end
end
function helpers.vertical_pad(height)
return wibox.widget {
forced_height = height,
layout = wibox.layout.fixed.vertical
}
end
function helpers.trim(str)
return str:gsub("%s+", "")
end
function helpers.split(source, sep)
local result, i = {}, 1
while true do
local a, b = source:find(sep)
if not a then
break
end
local candidat = source:sub(1, a - 1)
if candidat ~= "" then
result[i] = candidat
end
i = i + 1
source = source:sub(b + 1)
end
if source ~= "" then
result[i] = source
end
return result
end
function helpers.create_slider_meter_widget(args)
local image = args.image
local text = args.text
local slider = args.slider
local hight = args.hight
local left = args.left or dpi(24)
local right = args.right or dpi(24)
local slider_top = args.slider_top or dpi(20)
local slider_bottom = args.slider_bottom or dpi(12)
local slider_left = args.slider_left or dpi(0)
local slider_right = args.slider_right or dpi(40)
local text_top = args.text_top or dpi(12)
local text_bottom = args.text_bottom or dpi(12)
local text_left = args.text_left or dpi(0)
local text_right = args.text_right or dpi(0)
local image_top = args.image_top or dpi(12)
local image_bottom = args.image_bottom or dpi(12)
local image_left = args.image_left or dpi(0)
local image_right = args.image_right or dpi(0)
local cpu_meter =
wibox.widget {
{
{
{
image = image,
resize = true,
widget = wibox.widget.imagebox
},
point = function(geo, args)
return {
x = args.parent.width - geo.width,
y = (args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end,
top = image_top,
bottom = image_bottom,
left = image_left,
right = image_right,
widget = wibox.container.margin
},
{
{
text = text,
font = beautiful.uifont,
align = "center",
valign = "center",
widget = wibox.widget.textbox
},
point = function(geo, args)
return {
x = args.parent.width - geo.width,
y = (args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end,
top = text_top,
bottom = text_bottom,
left = text_left,
right = text_right,
widget = wibox.container.margin
},
{
slider,
top = slider_top,
bottom = slider_bottom,
left = slider_left,
right = slider_right,
widget = wibox.container.margin
},
layout = wibox.layout.manual
},
left = left,
right = right,
forced_height = hight or dpi(48),
widget = wibox.container.margin
}
local myclock_t = awful.tooltip {}
myclock_t:add_to_object(cpu_meter)
cpu_meter:connect_signal(
"mouse::enter",
function()
myclock_t.text = slider.core:get_value()
end
)
return cpu_meter
end
function helpers.to_12(time)
local h, m = time:match("^(%d%d):(%d%d)$")
if tonumber(h) > 12 then
h = h - 12
end
if string.len(h) == 1 then
h = "0" .. h
end
return h .. ":" .. m
end
function helpers.create_gradient_color(args)
local type = args.type or "linear"
local from = args.from or {0, 0}
local to = args.to or {0, 200}
local color1 = args.color1 or "#7766fb"
local color2 = args.color2 or "#fe67a9"
local stops1 = args.stops1 or 0
local stops2 = args.stops2 or 1
local stops = args.stops or {{stops1, color1}, {stops2, color2}}
return {
type = type,
from = from,
to = to,
stops = stops
}
end
function helpers.add_margin(args)
local widget = args.widget
local top = args.top or dpi(0)
local bottom = args.bottom or dpi(0)
local left = args.left or dpi(0)
local right = args.right or dpi(0)
local right = args.right or dpi(0)
local visible = args.visible
local id = args.id
local forced_height = args.forced_height
local forced_width = args.forced_width
local margin = {
widget,
id = id,
top = top,
bottom = bottom,
left = left,
forced_height = forced_height,
forced_width = forced_width,
right = right,
visible = visible,
widget = wibox.container.margin
}
return margin
end
function helpers.create_weather_detailed(args)
local text_font = args.font or beautiful.uifont
local icon_font = args.font or beautiful.iconfont
local forced_width = args.forced_width or dpi(250)
local visible = args.visible
local temperature_id = args.temperature_id or "temperature_id"
local sky_status_id = args.sky_status_id or "sky_status_id"
local weather_icon_id = args.weather_icon_id or "weather_icon_id"
local temperature_time_id = args.temperature_time_id or "temperature_time_id"
local temperature_date_id = args.temperature_date_id or "temperature_date_id"
local temperature_city_id = args.temperature_city_id or "temperature_city_id"
local h_l_temperature_id = args.h_l_temperature_id or "h_l_temperature_id"
local moonrise_id = args.moonrise_id or "moonrise_id"
local sunrise_id = args.sunrise_id or "sunrise_id"
local weather_details =
wibox.widget {
layout = wibox.layout.manual,
visible = visible,
forced_height = dpi(110),
forced_width = forced_width,
{
-- اليسار
point = function(geo, args)
return {
x = 0,
y = 0 --(args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end,
layout = wibox.layout.fixed.horizontal,
{
layout = wibox.layout.manual,
{
point = function(geo, args)
return {
x = 0,
y = 0 --(args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end,
layout = wibox.layout.fixed.vertical,
{
text = "",
font = "JF Flat 20",
align = "left",
id = temperature_time_id,
widget = wibox.widget.textbox
},
{
text = "",
font = "JF Flat 11",
align = "left",
id = temperature_date_id,
widget = wibox.widget.textbox
},
helpers.add_margin {
widget = {
markup = "",
font = icon_font,
align = "left",
id = sunrise_id,
widget = wibox.widget.textbox
}
-- top = dpi(5)
},
helpers.add_margin {
widget = {
markup = "",
font = icon_font,
align = "left",
id = moonrise_id,
widget = wibox.widget.textbox
}
-- top = dpi(5)
}
},
{
point = function(geo, args)
return {
x = 0,
y = args.parent.height - geo.height
}
end,
layout = wibox.layout.fixed.vertical,
{
text = "",
font = "JF Flat 11",
align = "left",
id = temperature_city_id,
widget = wibox.widget.textbox
}
}
}
},
{
-- اليمين
point = function(geo, args)
return {
x = args.parent.width - geo.width,
y = 0
}
end,
layout = wibox.layout.fixed.horizontal,
{
layout = wibox.layout.fixed.vertical,
helpers.add_margin {
widget = {
layout = wibox.layout.fixed.horizontal,
helpers.add_margin {
widget = {
text = "",
id = weather_icon_id,
font = icon_font,
-- align = "left",
widget = wibox.widget.textbox
},
right = dpi(5)
},
helpers.add_margin {
widget = {
layout = wibox.container.scroll.horizontal,
-- max_size = 100,
-- fps = 60,
step_function = wibox.container.scroll.step_functions.waiting_nonlinear_back_and_forth,
speed = 50,
{
text = "",
id = sky_status_id,
font = text_font,
align = "left",
widget = wibox.widget.textbox
}
}
-- left = forced_width - 180
-- forced_width = forced_width - 130,
}
},
left = forced_width - 135
},
{
text = "",
font = "JF Flat 40",
align = "right",
id = temperature_id,
widget = wibox.widget.textbox
},
helpers.add_margin {
widget = {
text = "",
font = text_font,
align = "right",
id = h_l_temperature_id,
widget = wibox.widget.textbox
},
right = dpi(3)
}
}
}
}
return weather_details
end
function helpers.create_music_widget(args)
local text_font = args.text_font or beautiful.uifont
local artist_font = args.artist_font or text_font:sub(1, -3) .. " 9"
local icon_font = args.icon_font or beautiful.iconfont
local margin_top = args.margin_top or dpi(0)
local widget_bg = args.widget_bg or beautiful.widget_bg
local widget_fg = args.widget_fg or beautiful.fg_normal
local icon_bg = args.icon_bg
local icon_fg = args.icon_fg
local inner_image_shape = args.shape or helpers.rrect(dpi(11))
local buttons_group_shape = args.shape or helpers.rrect(dpi(11))
local handle_shape = gears.shape.circle
local bar_shape = args.handle_shape or beautiful.vol_bar_shape or helpers.rrect(dpi(11))
local bar_height = args.bar_height or beautiful.vol_bar_height or dpi(1)
local bar_color = args.bar_color or beautiful.vol_bar_color
local bar_active_color = args.bar_active_color or beautiful.vol_bar_active_color
local handle_color = args.handle_color or beautiful.vol_bar_handle_color
local handle_width = args.handle_width or 0
local handle_border_color = args.handle_border_color or beautiful.vol_handle_border_color
local handle_border_width = args.handle_border_width or beautiful.vol_handle_border_width
local buttons_group_bg_color = args.buttons_group_bg_color or widget_bg
local buttons_group_fg_color = args.buttons_group_fg_color or widget_fg
local final =
wibox.widget {
layout = wibox.layout.fixed.vertical,
{
layout = wibox.layout.fixed.horizontal,
id = "detailed_widget_id",
helpers.set_widget_block {
widget = helpers.set_widget_block {
widget = {
id = "image_id",
image = beautiful.music_back,
horizontal_fit_policy = "fit",
vertical_fit_policy = "fit",
valign = "center",
align = "center",
type = "normal",
resize = true,
forced_height = dpi(110),
forced_width = dpi(110),
widget = wibox.widget.imagebox
},
shape = inner_image_shape
-- bg = "#2b337c"
},
right = dpi(0),
left = dpi(12),
top = dpi(12),
bottom = dpi(6),
bg = widget_bg,
fg = widget_fg
},
helpers.set_widget_block {
widget = {
layout = wibox.layout.fixed.vertical,
{
layout = wibox.layout.manual,
forced_height = dpi(40),
{
layout = wibox.layout.fixed.horizontal,
point = function(geo, args)
return {
x = args.parent.width - geo.width - dpi(12),
y = (args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end,
{
text = "🎝",
font = icon_font,
id = "music_icon_id",
align = "center",
valign = "center",
widget = wibox.widget.textbox
}
}
},
helpers.add_margin {
widget = {
layout = wibox.container.scroll.horizontal,
-- max_size = 100,
fps = 60,
step_function = wibox.container.scroll.step_functions.waiting_nonlinear_back_and_forth,
speed = 100,
id = "title_scroll_id",
{
id = "title_id",
text = "لا توجد موسيقى قيد التشغيل",
font = text_font,
align = "center",
valign = "center",
widget = wibox.widget.textbox
}
},
right = dpi(12),
left = dpi(12),
top = -5
},
helpers.add_margin {
widget = {
layout = wibox.container.scroll.horizontal,
-- max_size = 100,
-- forced_height = dpi(5),
fps = 60,
step_function = wibox.container.scroll.step_functions.waiting_nonlinear_back_and_forth,
speed = 100,
id = "artist_scroll_id",
{
id = "artist_id",
text = "لا يوجد فنان",
font = artist_font, --"JF Flat 9",
align = "left",
valign = "left",
widget = wibox.widget.textbox
}
},
right = dpi(12),
top = dpi(8),
bottom = dpi(8),
left = dpi(12)
},
helpers.add_margin {
widget = helpers.set_widget_block {
widget = {
layout = wibox.layout.manual,
{
point = function(geo, args)
return {
x = 10,
y = (args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end,
layout = wibox.layout.fixed.horizontal,
{
id = "back_button_id",
text = "",
font = icon_font,
align = "center",
valign = "center",
widget = wibox.widget.textbox
}
},
{
point = function(geo, args)
return {
x = (args.parent.width / 3) - 2,
y = (args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end,
layout = wibox.layout.fixed.horizontal,
{
id = "play_button_id",
text = "",
font = icon_font,
align = "center",
valign = "center",
widget = wibox.widget.textbox
}
},
{
point = function(geo, args)
return {
x = args.parent.width - (args.parent.width / 3) - geo.width,
y = (args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end,
layout = wibox.layout.fixed.horizontal,
{
id = "stop_button_id",
text = "",
font = icon_font,
align = "center",
valign = "center",
widget = wibox.widget.textbox
}
},
{
point = function(geo, args)
return {
x = args.parent.width - geo.width - 10,
y = (args.parent.height / 2 + (geo.height / 2)) - geo.height
}
end,
layout = wibox.layout.fixed.horizontal,
{
id = "next_button_id",
text = "",
font = icon_font,
align = "center",
valign = "center",
widget = wibox.widget.textbox
}
}
},
bg = buttons_group_bg_color,
fg = buttons_group_fg_color,
forced_height = dpi(27),
shape = buttons_group_shape
},
bottom = dpi(0),
top = dpi(10),
right = dpi(18),
left = dpi(12)
}
},
bg = widget_bg,
fg = widget_fg
}
},
helpers.set_widget_block {
widget = {
id = "progress",
bar_shape = bar_shape,
bar_height = bar_height,
bar_color = bar_color,
bar_active_color = bar_active_color,
bar_active_shape = bar_shape,
handle_color = handle_color,
handle_shape = handle_shape,
handle_border_color = handle_border_color,
handle_width = handle_width,
handle_border_width = handle_border_width,
value = 0,
maximum = 100,
widget = wibox.widget.slider
},
bg = widget_bg,
left = dpi(12),
right = dpi(12),
bottom = dpi(6),
top = margin_top
}
}
return final
end
return helpers