Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
can read config object and generate conf file
Browse files Browse the repository at this point in the history
  • Loading branch information
flickowoa committed Nov 19, 2022
1 parent 3488cf4 commit cef60e6
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 10 deletions.
5 changes: 5 additions & 0 deletions hyprkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ func main() {
fmt.Println(err)
}
fmt.Printf("%s\n", data)
save := parser.BuildConf(config)
err = ioutil.WriteFile("test/hyprland-generated.conf", []byte(save), 0644)
if err != nil {
panic(err)
}
}
}
}
157 changes: 157 additions & 0 deletions test/hyprland-generated.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#-----------------------------#
# Generated By HyprKeys #
#-----------------------------#

$mainMod = SUPER
$TERM = kitty
$FILES = dolphin

bind = $mainMod, Q, exec, kitty
bind = $mainMod, C, killactive,
bind = $mainMod, M, exit,
bind = $mainMod, E, exec, dolphin
bind = $mainMod, V, togglefloating,
bind = $mainMod, R, exec, wofi --show drun
bind = $mainMod, P, pseudo,
bind = $mainMod, J, togglesplit,

general {
sensitivity = 1
apply_sens_to_raw = false
main_mod = SUPER
border_size = 2
no_border_on_floating = false
gaps_in = 5
gaps_out = 12
col.active_border = rgba(1affffee)
col.inactive_border = rgba(595959aa)
cursor_inactive_timeout = 0
no_cursor_warps = false
layout = dwindle
}

misc {
disable_hyprland_logo = false
disable_splash_rendering = false
no_vfr = true
damage_entire_on_snapshot = false
mouse_move_enables_dpms = false
always_follow_on_dnd = true
layers_hog_keyboard_focus = true
animate_manual_resizes = false
disable_autoreload = false
enable_swallow = false
swallow_regex =
focus_on_activate = true
no_direct_scanout = false
}

debug {
log_damage = false
overlay = false
damage_blink = false
disable_logs = false
disable_time = true
damage_tracking = 2
}

decoration {
rounding = 6
blur = true
blur_size = 3
blur_passes = 1
blur_ignore_opacity = false
blur_new_optimizations = true
active_opacity = 1
inactive_opacity = 1
fullscreen_opacity = 1
multisample_edges = true
no_blur_on_oversized = false
drop_shadow = true
shadow_range = 4
shadow_render_power = 3
shadow_ignore_window = true
shadow_offset = [0 0]
col.shadow = rgba(1a1a1aee)
col.shadow_inactive = 0xee1a1a1a
dim_inactive = false
dim_strength = 0.5
}

dwindle {
pseudotile = true
col.group_border = 0x66777700
col.group_border_active = 0x66ffff00
force_split = 0
preserve_split = true
special_scale_factor = 0.8
split_width_multiplier = 1
no_gaps_when_only = false
use_active_for_splits = true
}

master {
special_scale_factor = 0.8
new_is_master = true
new_on_top = false
no_gaps_when_only = false
}

animations {
enabled = true
use_resize_transitions = false
}

input {
sensitivity = 0
accel_profile =
kb_file =
kb_layout = us
kb_variant =
kb_options =
kb_rules =
kb_model =
repeat_rate = 25
repeat_delay = 600
natural_scroll = false
numlock_by_default = false
force_no_accel = false
float_switch_override_focus = 1
left_handed = false
scroll_method =
touchpad {
natural_scroll = false
disable_while_typing = true
clickfinger_behavior = false
middle_button_emulation = false
tap_to_click = true
drag_lock = false
scroll_factor = 1
transform = 0
output =
}
touchdevice {
transform = 0
output =
}
follow_mouse = 1
}

binds {
pass_mouse_when_bound = false
scroll_event_delay = 300
workspace_back_and_forth = false
allow_workspace_cycles = false
}

gestures {
workspace_swipe = false
workspace_swipe_fingers = 3
workspace_swipe_distance = 300
workspace_swipe_invert = true
workspace_swipe_min_speed_to_force = 30
workspace_swipe_cancel_ratio = 0.5
workspace_swipe_create_new = true
workspace_swipe_forever = false
}

20 changes: 10 additions & 10 deletions test/hyprland.conf
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ gestures {

# Example per-device config
# See https://wiki.hyprland.org/Configuring/Keywords/#executing for more
device:epic mouse V1 {
sensitivity = -0.5
}
#device:epic mouse V1 {
# sensitivity = -0.5
#}

# Example windowrule v1
# windowrule = float, ^(kitty)$
Expand All @@ -113,13 +113,13 @@ $FILES = dolphin

# Example binds, see https://wiki.hyprland.org/Configuring/Binds/ for more
bind = $mainMod, Q, exec, kitty
#bind = $mainMod, C, killactive,
#bind = $mainMod, M, exit,
#bind = $mainMod, E, exec, dolphin
#bind = $mainMod, V, togglefloating,
#bind = $mainMod, R, exec, wofi --show drun
#bind = $mainMod, P, pseudo, # dwindle
#bind = $mainMod, J, togglesplit, # dwindle
bind = $mainMod, C, killactive,
bind = $mainMod, M, exit,
bind = $mainMod, E, exec, dolphin
bind = $mainMod, V, togglefloating,
bind = $mainMod, R, exec, wofi --show drun
bind = $mainMod, P, pseudo, # dwindle
bind = $mainMod, J, togglesplit, # dwindle
#
## Move focus with mainMod + arrow keys
#bind = $mainMod, left, movefocus, l
Expand Down
73 changes: 73 additions & 0 deletions util/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,76 @@ func Parse(content string) props.Config {
blocks := ParseBlocks(content)
return ParseConfig(blocks)
}

func BuildGlobal(glob props.S_global) string {
var out string
for key, val := range glob.S_variables {
out += key + " = " + val + "\n"
}
out += "\n"
for _, binds := range glob.S_binds {
for key, val := range binds {
out += key + " = " + strings.Join(val, ",") + "\n"
}
}
out += glob.S_raw
return out
}

func BuildConf(conf props.Config) string {
output := "#-----------------------------#\n# Generated By HyprKeys #\n#-----------------------------#\n\n"
fields, err := reflections.Fields(conf)
if err != nil {
fmt.Println("error getting fields", err)
}
for _, field := range fields {
block, err := reflections.GetField(conf, field)
if err != nil {
fmt.Println("error getting block", err)
continue
}
field = strings.Replace(field, "S_", "", 1)
field = strings.ToLower(field)
if field == "global" {
output += BuildGlobal(*conf.Global)
continue
}
output += field
output += " {\n"
block_fields, err := reflections.Fields(block)
if err != nil {
fmt.Println("error getting block fields", err)
continue
}
for _, block_field := range block_fields {
val, err := reflections.GetField(block, block_field)
if err != nil {
fmt.Println("error getting block field", err)
continue
}
block_field = strings.Replace(block_field, "__", ".", 1)
block_field = strings.TrimPrefix(block_field, "S_")
val_fields, err := reflections.Fields(val)
if val_fields == nil || err != nil {
fmt.Println(val_fields, err)
output += " " + block_field + " = " + fmt.Sprint(val) + "\n"
} else {
fmt.Println("got field: ", val_fields)
output += " " + block_field + " {\n"
for _, val_field := range val_fields {
val_val, err := reflections.GetField(val, val_field)
if err != nil {
fmt.Println("error getting block field", err)
continue
}
val_field = strings.Replace(val_field, "__", ".", 1)
val_field = strings.TrimPrefix(val_field, "S_")
output += " " + val_field + " = " + fmt.Sprint(val_val) + "\n"
}
output += " }\n"
}
}
output += "}\n\n"
}
return output
}

0 comments on commit cef60e6

Please sign in to comment.