From 76e154f426f93c421967ce06e06070a0d2934f23 Mon Sep 17 00:00:00 2001 From: Arda Atci Date: Mon, 11 Dec 2023 00:56:27 +0300 Subject: [PATCH] picom page done --- animations.go | 65 --------------- main.go | 20 +---- picom/animations.go | 187 ++++++++++++++++++++++++++++++++++++++++++++ picom/picomopts.go | 177 +++++++++++++++++++++++++++++++++++++++++ utils/utils.go | 3 + 5 files changed, 371 insertions(+), 81 deletions(-) delete mode 100644 animations.go create mode 100644 picom/animations.go create mode 100644 picom/picomopts.go diff --git a/animations.go b/animations.go deleted file mode 100644 index 03f8371..0000000 --- a/animations.go +++ /dev/null @@ -1,65 +0,0 @@ -package main - -import ( - "github.com/gotk3/gotk3/gtk" -) - -// Setup the TextView, put it in a ScrolledWindow, and add both to box. -func setupTextView(box *gtk.Box) *gtk.TextView { - sw, _ := gtk.ScrolledWindowNew(nil, nil) - tv, _ := gtk.TextViewNew() - sw.Add(tv) - box.PackStart(sw, true, true, 0) - return tv -} - -func comboBoxNewWithLabel(s string, o gtk.Orientation) *gtk.Box { - lbl, _ := gtk.LabelNew(s) - box, _ := gtk.BoxNew(o, 10) - cbx, _ := gtk.ComboBoxNew() - - box.Add(lbl) - box.Add(cbx) - - return box -} - -// func setupPropertyCheckboxes(tv *gtk.TextView, outer *gtk.Box, props []*BoolProperty) { -// box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0) -// for _, prop := range props { -// chk, _ := gtk.CheckButtonNewWithLabel(prop.Name) -// // initialize the checkbox with the property's current value -// chk.SetActive(prop.Get()) -// p := prop // w/o this all the checkboxes will toggle the last property in props -// chk.Connect("toggled", func() { -// p.Set(chk.GetActive()) -// }) -// box.PackStart(chk, true, true, 0) -// } -// outer.PackStart(box, false, false, 0) -// } - -func setupAnimationsTab() *gtk.Box{ - box := boxNew(gtk.ORIENTATION_VERTICAL, 0) - - // tv := setupTextView(box) - - chkGlx, _ := gtk.CheckButtonNewWithLabel(": Use GLX") - chkVsync, _ := gtk.CheckButtonNewWithLabel(": Enable VSync") - chkAnimations, _ := gtk.CheckButtonNewWithLabel(": Enable Animations") - chkFading, _ := gtk.CheckButtonNewWithLabel(": Enable Fading") - chkNextTagFading, _ := gtk.CheckButtonNewWithLabel(": Next Tag Fading") - chkPrevTagFading, _ := gtk.CheckButtonNewWithLabel(": Prev Tag Fading") - - cbx := comboBoxNewWithLabel("Hello", gtk.ORIENTATION_HORIZONTAL) - - box.Add(chkGlx) - box.Add(chkVsync) - box.Add(chkAnimations) - box.Add(chkFading) - box.Add(chkNextTagFading) - box.Add(chkPrevTagFading) - box.Add(cbx) - - return box -} diff --git a/main.go b/main.go index 1503123..668cda4 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,9 @@ package main - import ( - "github.com/gotk3/gotk3/gtk" "log" + "github.com/gotk3/gotk3/gtk" + p "physettings/picom" ) const ( @@ -13,18 +13,6 @@ const ( logo_path = "/usr/share/pixmaps/phyOS-logo-128x128.png" ) -func boxNew(o gtk.Orientation, spc int) *gtk.Box { - - box, err := gtk.BoxNew(o, spc) - - if err != nil { - log.Fatal("Error: Can not create box", err) - } - - return box -} - - func imageNew(path string) *gtk.Image { img, err := gtk.ImageNewFromFile(path) @@ -82,7 +70,7 @@ func main() { nb.SetVExpand(true) logo := imageNew(logo_path) - box := boxNew(gtk.ORIENTATION_VERTICAL, 15) + box, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 15) logo.SetHAlign(gtk.ALIGN_CENTER) box.SetMarginStart(spacing) box.SetMarginTop(spacing) @@ -101,7 +89,7 @@ func main() { nb.AppendPage(box, nbInfo) nb.AppendPage(nbChild, nbOptions) - animationsBox := setupAnimationsTab() + animationsBox := p.SetupAnimationsTab() nb.AppendPage(animationsBox, nbAnimations) win.ShowAll() diff --git a/picom/animations.go b/picom/animations.go new file mode 100644 index 0000000..e243e89 --- /dev/null +++ b/picom/animations.go @@ -0,0 +1,187 @@ +package picom + +import ( + "log" + "strconv" + + "github.com/gotk3/gotk3/gtk" +) + +const ( + spaceSize = 10 +) + +type ComboBoxLabel struct { + Box *gtk.Box + ComboBox *gtk.ComboBoxText +} + +type SpinButtonLabel struct { + Box *gtk.Box + SpinButton *gtk.SpinButton +} + +// Setup the TextView, put it in a ScrolledWindow, and add both to box. +func setupTextView(box *gtk.Box) *gtk.TextView { + sw, _ := gtk.ScrolledWindowNew(nil, nil) + tv, _ := gtk.TextViewNew() + sw.Add(tv) + box.PackStart(sw, true, true, 0) + return tv +} + +func comboBoxAddEntries(s []string, cbx *gtk.ComboBoxText) { + for _, val := range s { + cbx.AppendText(val) + } + cbx.SetActive(0) +} + +func comboBoxNewWithLabel(s string, o gtk.Orientation) *ComboBoxLabel { + lbl, _ := gtk.LabelNew(s) + box, _ := gtk.BoxNew(o, spaceSize) + cbx, _ := gtk.ComboBoxTextNew() + + box.Add(lbl) + box.Add(cbx) + + return &ComboBoxLabel{box, cbx} +} + +func spinButtonNewWithLabel(s string, o gtk.Orientation, mn, mx, stp float64) *SpinButtonLabel { + lbl, _ := gtk.LabelNew(s) + box, _ := gtk.BoxNew(o, spaceSize) + spn, _ := gtk.SpinButtonNewWithRange(mn, mx, stp) + box.Add(lbl) + box.Add(spn) + return &SpinButtonLabel{box, spn} +} + +func SetupAnimationsTab() *gtk.Box{ + readPicomOpts() + box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0) + boxLeft, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5) + boxRight, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5) + boxLeft.SetHExpand(true) + + chkAnimations, _ := gtk.CheckButtonNewWithLabel(": Enable Animations") + chkFading, _ := gtk.CheckButtonNewWithLabel(": Enable Fading") + chkNextTagFading, _ := gtk.CheckButtonNewWithLabel(": Next Tag Fading") + chkPrevTagFading, _ := gtk.CheckButtonNewWithLabel(": Prev Tag Fading") + chkGlx, _ := gtk.CheckButtonNewWithLabel(": Use GLX") + chkVsync, _ := gtk.CheckButtonNewWithLabel(": Enable VSync") + chkShadow, _ := gtk.CheckButtonNewWithLabel(": Enable Shadows") + + isChecked := func(chk *gtk.CheckButton, s string) { + if picomOpts[s] == "false" { + return + } + chk.SetActive(true) + } + isChecked(chkAnimations, _animations) + isChecked(chkFading, _fading) + isChecked(chkNextTagFading, _enable_fading_next_tag) + isChecked(chkPrevTagFading, _enable_fading_prev_tag) + isChecked(chkVsync, _vsync) + isChecked(chkGlx, _backend) + isChecked(chkShadow, _shadow) + + spnAnimSpeedInTag := spinButtonNewWithLabel("Anim Speed in Tag: ", + gtk.ORIENTATION_HORIZONTAL, + 30, 250, 1) + spnAnimSpeedInTag.SpinButton.SetValue(stof(picomOpts[_animation_stiffness_in_tag])) + spnAnimSpeedOnTagChange := spinButtonNewWithLabel("Anim Speed on Tag Change: ", + gtk.ORIENTATION_HORIZONTAL, + 30, 250, 1) + spnAnimSpeedOnTagChange.SpinButton.SetValue(stof(picomOpts[_animation_stiffness_tag_change])) + + cmbOpenWindowAnim := comboBoxNewWithLabel("Open Window Anim: ", gtk.ORIENTATION_HORIZONTAL) + comboBoxAddEntries(animOpenOpts, cmbOpenWindowAnim.ComboBox) + cmbCloseWindowAnim := comboBoxNewWithLabel("Close Window Anim: ", gtk.ORIENTATION_HORIZONTAL) + comboBoxAddEntries(animCloseOpts, cmbCloseWindowAnim.ComboBox) + cmbPrevTag := comboBoxNewWithLabel("Anim For Prev Tag: ", gtk.ORIENTATION_HORIZONTAL) + comboBoxAddEntries(animPrevOpts, cmbPrevTag.ComboBox) + cmbNextTag := comboBoxNewWithLabel("Anim For Next Tag: ", gtk.ORIENTATION_HORIZONTAL) + comboBoxAddEntries(animNextOpts, cmbNextTag.ComboBox) + + boxLeft.Add(chkGlx) + boxLeft.Add(chkVsync) + boxLeft.Add(chkAnimations) + boxLeft.Add(chkFading) + boxLeft.Add(chkNextTagFading) + boxLeft.Add(chkPrevTagFading) + boxLeft.Add(chkShadow) + + boxRight.Add(spnAnimSpeedInTag.Box) + boxRight.Add(spnAnimSpeedOnTagChange.Box) + boxRight.Add(cmbOpenWindowAnim.Box) + boxRight.Add(cmbCloseWindowAnim.Box) + boxRight.Add(cmbPrevTag.Box) + boxRight.Add(cmbNextTag.Box) + + pb, _ := gtk.ButtonNewWithLabel("Save Changes") + pb.SetMarginStart(20) + + pb.Connect("clicked", func(){ + if chkAnimations.GetActive() { + changePicomAttribute(_animations, "true", false) + } else { + changePicomAttribute(_animations, "false", false) + } + + if chkGlx.GetActive() { + changePicomAttribute(_backend, "glx", true) + } else { + changePicomAttribute(_backend, "xrender", true) + } + + if chkVsync.GetActive() { + changePicomAttribute(_vsync, "true", false) + } else { + changePicomAttribute(_vsync, "false", false) + } + + if chkShadow.GetActive() { + changePicomAttribute(_shadow, "true", false) + } else { + changePicomAttribute(_shadow, "false", false) + } + + if chkFading.GetActive() { + changePicomAttribute(_fading, "true", false) + } else { + changePicomAttribute(_fading, "false", false) + } + + if chkNextTagFading.GetActive() { + changePicomAttribute(_enable_fading_next_tag, "true", false) + } else { + changePicomAttribute(_enable_fading_next_tag, "false", false) + } + + if chkPrevTagFading.GetActive() { + changePicomAttribute(_enable_fading_prev_tag, "true", false) + } else { + changePicomAttribute(_enable_fading_prev_tag, "false", false) + } + + picomOpts[_animation_stiffness_in_tag] = strconv.FormatFloat(spnAnimSpeedInTag.SpinButton.GetValue(), 'f', 1, 64) + picomOpts[_animation_stiffness_tag_change] = strconv.FormatFloat(spnAnimSpeedOnTagChange.SpinButton.GetValue(), 'f', 1, 64) + + changePicomAttribute(_animation_stiffness_in_tag, picomOpts[_animation_stiffness_in_tag], false) + changePicomAttribute(_animation_stiffness_tag_change, picomOpts[_animation_stiffness_tag_change], false) + + + err := savePicomOpts() + if err != nil { + log.Fatal(err.Error()) + } + }) + + + box.Add(boxLeft) + box.Add(boxRight) + box.Add(pb) + + return box +} diff --git a/picom/picomopts.go b/picom/picomopts.go new file mode 100644 index 0000000..ee787c3 --- /dev/null +++ b/picom/picomopts.go @@ -0,0 +1,177 @@ +package picom + +import ( + "fmt" + "os" + "os/exec" + "strconv" + "strings" +) + +var picomConfPath string + +const ( + _animations = "animations" + _fading = "fading" + _enable_fading_next_tag = "enable-fading-next-tag" + _enable_fading_prev_tag = "enable-fading-prev-tag" + _animation_stiffness_in_tag = "animation-stiffness-in-tag" + _animation_stiffness_tag_change = "animation-stiffness-tag-change" + _animation_for_open_window = "animation-for-open-window" + _animation_for_unmap_window = "animation-for-unmap-window" + _animation_for_prev_tag = "animation-for-prev-tag" + _animation_for_next_tag = "animation-for-next-tag" + _vsync = "vsync" + _backend = "backend" + _shadow = "shadow" +) + +var picomOpts = map[string]string { + _animations : "false", + _fading : "false", + _animation_stiffness_in_tag : "0", + _animation_stiffness_tag_change : "0", + _animation_for_open_window : "none", + _animation_for_unmap_window : "none", + _animation_for_prev_tag : "none", + _animation_for_next_tag : "none", + _enable_fading_next_tag : "false", + _enable_fading_prev_tag : "false", + _vsync : "false", + _shadow : "false", + _backend : "glx", +} + +var animInfo = map[string]string { + "fly-in" : "Windows fly in from random directions to the screen.", + "maximize" : "Windows pop from center of the screen to their respective positions.", + "minimize" : "Windows minimize from their position to the center of the screen.", + "slide-in-center" : "Windows move from upper-center of the screen to their respective positions.", + "slide-out-center" : "Windows move to the upper-center of the screen.", + "slide-left" : "Windows are created from the right-most window position and slide leftwards.", + "slide-right" : "Windows are created from the left-most window position and slide rightwards.", + "slide-down" : "Windows are moved from the top of the screen and slide downward.", + "slide-up" : "Windows are moved from their position to top of the screen.", + "squeeze" : "Windows are either closed or created to/from their center y-position (the animation is similar to a blinking eye).", + "squeeze-bottom" : "Similar to squeeze, but the animation starts from bottom-most y-position.", + "zoom" : "Windows are either created or destroyed from/to their center (not the screen center).", +} + +var animOpenOpts = []string{ + "fly-in", + "slide-up", + "slide-down", + "slide-left", + "slide-right", + "squeeze", + "squeeze-bottom", + "zoom", +} + +var animCloseOpts = []string{ + "slide-out-center", + "squeeze", + "squeeze-bottom", + "zoom", +} + +var animPrevOpts = []string{ + "minimize", + "slide-out-center", + "slide-down", + "slide-up", + "squeeze", + "squeeze-bottom", + "zoom", +} + +var animNextOpts = []string { + "fly-in", + "maximize", + "slide-in-center", + "slide-down", + "slide-up", + "squeeze", + "squeeze-bottom", + "zoom", +} + +func stof(s string) float64 { + f, _ := strconv.ParseFloat(s, 64) + return f +} + +func changePicomAttribute(attribute, value string, isString bool) error { + picomOpts[attribute] = value + var cmd string + if isString { + cmd = fmt.Sprintf("sed -i '/^%s/c\\%s = \"%s\";' /tmp/picom.conf", attribute + "\\ =", attribute, value) + } else { + cmd = fmt.Sprintf("sed -i '/^%s/c\\%s = %s;' /tmp/picom.conf", attribute + "\\ =", attribute, value) + } + err := exec.Command("/bin/bash", "-c", cmd).Run() + + return err +} + +func readPicomOpts() { + home, _ := os.UserHomeDir(); home += "/.config/picom/picom.conf" + picomConfPath = home + cmd := fmt.Sprintf("cp -f %s /tmp/picom.conf", home) + exec.Command("/bin/bash", "-c", cmd).Start() + for key := range picomOpts { + var cmd string + if key == _fading { + cmd = fmt.Sprintf("grep -w \"%s\" \"%s\" | cut -f1 -d \";\" | tr -d '\"\\n'", "fading =", picomConfPath) + } else if key == _vsync { + cmd = fmt.Sprintf("grep -w \"%s\" \"%s\" | cut -f1 -d \";\" | tr -d '\"\\n'", "vsync =", picomConfPath) + } else if key == _backend { + cmd = fmt.Sprintf("grep -w \"%s\" \"%s\" | cut -f1 -d \";\" | tr -d '\"\\n'", "backend =", picomConfPath) + } else if key == _shadow { + cmd = fmt.Sprintf("grep -w \"^%s\" \"%s\" | cut -f1 -d \";\" | tr -d '\"\\n'", "shadow =", picomConfPath) + } else { + cmd = fmt.Sprintf("grep -r \"%s\" \"%s\" | cut -f1 -d \";\" | tr -d '\"\\n'", key, picomConfPath) + } + out, err := exec.Command("/bin/bash", "-c", cmd).Output() + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + } else { + s := strings.ReplaceAll(string(out), " ", "") + arr := strings.Split(s, "=") + if len(arr) > 1 { + picomOpts[key] = arr[1] + } + + search := func(cur string, arr []string) { + for i := 0; i < len(arr); i++ { + if arr[i] == cur { + arr[0], arr[i] = arr[i], arr[0] + break + } + } + } + + switch key { + case _animation_for_open_window: + search(arr[1], animOpenOpts) + case _animation_for_unmap_window: + search(arr[1], animCloseOpts) + case _animation_for_next_tag: + search(arr[1], animNextOpts) + case _animation_for_prev_tag: + search(arr[1], animPrevOpts) + + } + } + } +} + +func savePicomOpts() error { + cmd := fmt.Sprintf("cp -f /tmp/picom.conf %s", picomConfPath) + err := exec.Command("/bin/bash", "-c", cmd).Run() + + if err != nil { + return err + } + return nil +} diff --git a/utils/utils.go b/utils/utils.go index d754a8c..cb0669b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -8,6 +8,8 @@ import ( "os/exec" "strings" "time" + "github.com/gotk3/gotk3/gtk" + "log" ) const( @@ -31,6 +33,7 @@ var PowerMenuTypes []string var PowerMenuStyles []string var ScriptInfo map[string]string + func appendAttribute(attribute string) error { cmd := fmt.Sprintf("echo %s >> %s", attribute, settingsPath) return exec.Command("/bin/bash", "-c", cmd).Run()