mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-21 13:04:20 +02:00
Review part 3
This commit is contained in:
parent
6aa4a12fd2
commit
f988f0294a
27 changed files with 99 additions and 44 deletions
|
|
@ -3,6 +3,9 @@ brightness_down = خفض السطوع
|
|||
brightness_up = رفع السطوع
|
||||
capslock = capslock
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = فشل في تخصيص الذاكرة
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = намаляване на яркостта
|
|||
brightness_up = увеличаване на яркостта
|
||||
capslock = caps lock
|
||||
custom = персонализирано
|
||||
|
||||
|
||||
|
||||
err_alloc = неуспешно заделяне на памет
|
||||
err_args = неуспешен анализ на аргументите от командния ред
|
||||
err_autologin_session = сесията за автоматично влизане не е намерена
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = abaixar brillantor
|
|||
brightness_up = apujar brillantor
|
||||
capslock = Bloq Majús
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = assignació de memòria fallida
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
capslock = capslock
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = alokace paměti selhala
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = Helligkeit-
|
|||
brightness_up = Helligkeit+
|
||||
capslock = Feststelltaste
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = Speicherzuweisung fehlgeschlagen
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = decrease brightness
|
|||
brightness_up = increase brightness
|
||||
capslock = capslock
|
||||
custom = custom
|
||||
|
||||
|
||||
|
||||
err_alloc = failed memory allocation
|
||||
err_args = unable to parse command line arguments
|
||||
err_autologin_session = autologin session not found
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = malpliigi helecon
|
|||
brightness_up = pliigi helecon
|
||||
capslock = majuskla baskulo
|
||||
custom = propra
|
||||
|
||||
|
||||
|
||||
err_alloc = malsukcesis memorasignon
|
||||
err_args = ne povas analizi argumentojn de komanda linio
|
||||
err_autologin_session = aŭtomatan ensalutan seancon ne trovis
|
||||
|
|
@ -73,6 +76,7 @@ restart = restartigi
|
|||
shell = ŝelo
|
||||
shutdown = malŝalti
|
||||
sleep = memordormi
|
||||
|
||||
wayland = wayland
|
||||
x11 = x11
|
||||
xinitrc = xinitrc
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = bajar brillo
|
|||
brightness_up = subir brillo
|
||||
capslock = Bloq Mayús
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = asignación de memoria fallida
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = diminuer la luminosité
|
|||
brightness_up = augmenter la luminosité
|
||||
capslock = verr.maj
|
||||
custom = customisé
|
||||
|
||||
|
||||
|
||||
err_alloc = échec d'allocation mémoire
|
||||
err_args = échec de l'analyse des arguments en lignes de commande
|
||||
err_autologin_session = session de connexion automatique introuvable
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
capslock = capslock
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = impossibile allocare memoria
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = 明るさを下げる
|
|||
brightness_up = 明るさを上げる
|
||||
capslock = CapsLock
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = メモリ割り当て失敗
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = ronahiyê kêm bike
|
|||
brightness_up = ronahiyê bilind bike
|
||||
capslock = tîpên girdek (capslock)
|
||||
custom = kesane
|
||||
|
||||
|
||||
|
||||
err_alloc = veqetandina bîrê têk çû
|
||||
err_args = argumanên rêzika fermanê nehatin analîzkirin
|
||||
err_autologin_session = danişîna têketina xweber nehate dîtin
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = samazināt spilgtumu
|
|||
brightness_up = palielināt spilgtumu
|
||||
capslock = caps lock
|
||||
custom = pielāgots
|
||||
|
||||
|
||||
|
||||
err_alloc = neizdevās atmiņas piešķiršana
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = zmniejsz jasność
|
|||
brightness_up = zwiększ jasność
|
||||
capslock = capslock
|
||||
custom = własny
|
||||
|
||||
|
||||
|
||||
err_alloc = nieudana alokacja pamięci
|
||||
|
||||
err_autologin_session = nie znaleziono sesji autologowania
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
capslock = capslock
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = erro na atribuição de memória
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
capslock = caixa alta
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = alocação de memória malsucedida
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ capslock = capslock
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = уменьшить яркость
|
|||
brightness_up = увеличить яркость
|
||||
capslock = capslock
|
||||
custom = пользовательский
|
||||
|
||||
|
||||
|
||||
err_alloc = не удалось выделить память
|
||||
|
||||
err_autologin_session = не найдена сессия с автологином
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
capslock = capslock
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = neuspijesna alokacija memorije
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = minska ljusstyrka
|
|||
brightness_up = öka ljusstyrka
|
||||
capslock = capslock
|
||||
custom = anpassad
|
||||
|
||||
|
||||
|
||||
err_alloc = minnesallokering misslyckades
|
||||
err_args = tolkning av kommandoargument misslyckades
|
||||
err_autologin_session = autologin-session hittades inte
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ brightness_down = parlakligi azalt
|
|||
brightness_up = parlakligi arttir
|
||||
capslock = capslock
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = basarisiz bellek ayirma
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
capslock = capslock
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = невдале виділення пам'яті
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
capslock = 大写锁定
|
||||
|
||||
|
||||
|
||||
|
||||
err_alloc = 内存分配失败
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ brightness_down: []const u8 = "decrease brightness",
|
|||
brightness_up: []const u8 = "increase brightness",
|
||||
capslock: []const u8 = "capslock",
|
||||
custom: []const u8 = "custom",
|
||||
custom_info_err_output_long: []const u8 = "output too long",
|
||||
custom_info_err_no_output: []const u8 = "no output",
|
||||
custom_info_err_no_output_error: []const u8 = ", possible error",
|
||||
err_alloc: []const u8 = "failed memory allocation",
|
||||
err_args: []const u8 = "unable to parse command line arguments",
|
||||
err_autologin_session: []const u8 = "autologin session not found",
|
||||
|
|
|
|||
|
|
@ -5,15 +5,13 @@ const custom = @This();
|
|||
pub const CustomCommandBind = struct {
|
||||
name: []const u8 = "",
|
||||
cmd: []const u8 = "",
|
||||
posX: u32 = 0,
|
||||
posY: u32 = 0,
|
||||
};
|
||||
|
||||
pub const UNDEFINED_CMD: []const u8 = "echo \"You forgot to define 'cmd'!\"";
|
||||
|
||||
pub const CustomCommandInfo = struct {
|
||||
name: []const u8 = "",
|
||||
cmd: []const u8 = UNDEFINED_CMD,
|
||||
cmd: ?[]const u8 = null,
|
||||
/// To be set to the label widget's `lid`
|
||||
id: u64 = 0,
|
||||
|
||||
|
|
@ -21,10 +19,6 @@ pub const CustomCommandInfo = struct {
|
|||
/// If 0, only run once.
|
||||
refresh: u32 = 0,
|
||||
counter: u32 = 0,
|
||||
posX: u32 = 0,
|
||||
posY: u32 = 0,
|
||||
invertY: bool = false,
|
||||
invertX: bool = false,
|
||||
};
|
||||
|
||||
pub var binds: std.StringHashMap(CustomCommandBind) = undefined;
|
||||
|
|
|
|||
|
|
@ -176,12 +176,6 @@ pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniFie
|
|||
if (std.mem.eql(u8, field.key, "cmd")) {
|
||||
command.cmd = temporary_allocator.dupe(u8, field.value) catch "";
|
||||
}
|
||||
if (std.mem.eql(u8, field.key, "posX")) {
|
||||
command.posX = std.fmt.parseInt(u32, field.value, 10) catch 0;
|
||||
}
|
||||
if (std.mem.eql(u8, field.key, "posY")) {
|
||||
command.posY = std.fmt.parseInt(u32, field.value, 10) catch 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -197,22 +191,10 @@ pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniFie
|
|||
if (std.mem.eql(u8, field.key, "cmd")) {
|
||||
label.cmd = temporary_allocator.dupe(u8, field.value) catch "";
|
||||
}
|
||||
if (std.mem.eql(u8, field.key, "posX")) {
|
||||
label.posX = std.fmt.parseInt(u32, field.value, 10) catch 0;
|
||||
}
|
||||
if (std.mem.eql(u8, field.key, "posY")) {
|
||||
label.posY = std.fmt.parseInt(u32, field.value, 10) catch 0;
|
||||
}
|
||||
if (std.mem.eql(u8, field.key, "refresh")) {
|
||||
label.refresh = std.fmt.parseInt(u32, field.value, 10) catch 0;
|
||||
label.refresh += 1;
|
||||
}
|
||||
if (std.mem.eql(u8, field.key, "invertX")) {
|
||||
label.invertX = if (std.mem.eql(u8, field.value, "true")) true else false;
|
||||
}
|
||||
if (std.mem.eql(u8, field.key, "invertY")) {
|
||||
label.invertY = if (std.mem.eql(u8, field.value, "true")) true else false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
44
src/main.zig
44
src/main.zig
|
|
@ -237,8 +237,8 @@ pub fn main() !void {
|
|||
var labelIter = custom.labels.iterator();
|
||||
while (labelIter.next()) |i| {
|
||||
temporary_allocator.free(i.key_ptr.*);
|
||||
if (i.value_ptr.cmd.ptr != custom.UNDEFINED_CMD.ptr)
|
||||
temporary_allocator.free(i.value_ptr.*.cmd);
|
||||
if (i.value_ptr.cmd) |cmd|
|
||||
temporary_allocator.free(cmd);
|
||||
}
|
||||
custom.labels.deinit();
|
||||
}
|
||||
|
|
@ -1769,11 +1769,15 @@ fn updateCustomInfo(lbl: *Label, ptr: *anyopaque) !void {
|
|||
defer stderr.deinit(state.allocator);
|
||||
for (state.custom_info.items) |*i| {
|
||||
if (i.info.id != wid) continue;
|
||||
// Here, a counter ticks down every time `updateCustomInfo` runs on that
|
||||
// particular label. It will only run the command and update the label
|
||||
// once it reaches to 1. If a refresh value is defined it's then reset to
|
||||
// that refresh value.
|
||||
if (i.info.counter == 1) {
|
||||
var c = std.process.Child.init(&[_][]const u8 {
|
||||
"/bin/sh",
|
||||
"-c",
|
||||
i.info.cmd
|
||||
i.info.cmd orelse custom.UNDEFINED_CMD
|
||||
}, state.allocator);
|
||||
c.stderr_behavior = .Pipe;
|
||||
c.stdout_behavior = .Pipe;
|
||||
|
|
@ -1781,7 +1785,7 @@ fn updateCustomInfo(lbl: *Label, ptr: *anyopaque) !void {
|
|||
|
||||
|
||||
c.collectOutput(state.allocator, &stdout, &stderr, state.buffer.width) catch {
|
||||
try stdout.print(state.allocator, "{s}: [Output too long]", .{i.info.name});
|
||||
try stdout.print(state.allocator, "{s}: [{s}]", .{i.info.name, state.lang.custom_info_err_output_long});
|
||||
};
|
||||
|
||||
const newlineIdx = std.mem.indexOfAny(u8, stdout.items, "\n");
|
||||
|
|
@ -1791,23 +1795,27 @@ fn updateCustomInfo(lbl: *Label, ptr: *anyopaque) !void {
|
|||
|
||||
if (stdout.items.len > state.buffer.width) {
|
||||
stdout.clearRetainingCapacity();
|
||||
try stdout.print(state.allocator, "{s}: [Output too long]", .{i.info.name});
|
||||
try stdout.print(state.allocator, "{s}: [{s}]", .{i.info.name, state.lang.custom_info_err_output_long});
|
||||
}
|
||||
|
||||
_ = try c.wait();
|
||||
|
||||
// Sometimes, the output of a command would have an unprintable character at
|
||||
// the end of its output, causing '<27>' to appear in its place. Here, we check
|
||||
// if this is the case and remove it.
|
||||
if (stdout.items.len != 0 and !std.ascii.isPrint(stdout.items[stdout.items.len-1])) {
|
||||
_ = stdout.pop();
|
||||
} else if (stdout.items.len == 0) {
|
||||
try stdout.print(state.allocator, "{s}: [No output{s}]", .{
|
||||
try stdout.print(state.allocator, "{s}: [{s}{s}]", .{
|
||||
i.info.name,
|
||||
if (stderr.items.len > 0) ": Possible Error" else ""
|
||||
state.lang.custom_info_err_no_output,
|
||||
if (stderr.items.len > 0) state.lang.custom_info_err_no_output_error else ""
|
||||
});
|
||||
}
|
||||
state.allocator.free(lbl.text);
|
||||
lbl.text = try state.allocator.dupe(u8, stdout.items);
|
||||
|
||||
// we reposition the widgets in the event of a inverted label.
|
||||
// not doing so causes the inverted label to not be positioned correctly
|
||||
// Called to re-position the widgets after they receive their output.
|
||||
try positionWidgets(state);
|
||||
if (i.info.refresh != 0)
|
||||
i.info.counter = i.info.refresh;
|
||||
|
|
@ -1911,19 +1919,17 @@ fn positionWidgets(ptr: *anyopaque) !void {
|
|||
state.brightness_up_label.positionXY(last_label
|
||||
.childrenPosition()
|
||||
.addX(1));
|
||||
for (state.custom_binds.items) |*item| {
|
||||
for (state.custom_binds.items, 1..) |*item, i| {
|
||||
item.lbl.positionXY(state.edge_margin
|
||||
.addX(@intCast(item.cmd.posX))
|
||||
.addY(@intCast(item.cmd.posY)));
|
||||
.addY(@intCast(i)));
|
||||
}
|
||||
for (state.custom_info.items) |*item| {
|
||||
for (state.custom_info.items, 0..) |*item, i| {
|
||||
item.lbl.positionXY(state.edge_margin
|
||||
.addX(@intCast(item.info.posX))
|
||||
.addY(@intCast(item.info.posY))
|
||||
.invertXIf(state.buffer.width, item.info.invertX)
|
||||
.removeXIf(item.lbl.text.len, item.info.invertX)
|
||||
.invertYIf(state.buffer.height, item.info.invertY)
|
||||
.removeYIf(1, item.info.invertY));
|
||||
.addY(@intCast(i))
|
||||
.invertX(state.buffer.width)
|
||||
.removeX(item.lbl.text.len)
|
||||
.invertY(state.buffer.height)
|
||||
.removeY(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue