Skip to content

Commit

Permalink
feat: merge behavior should now be fully implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ledif committed Feb 26, 2025
1 parent e62834d commit 5594647
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 11 deletions.
44 changes: 42 additions & 2 deletions src/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package main

import (
"bufio"
"bytes"
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)
Expand All @@ -23,6 +25,8 @@ func gatherDefaultPropertyValuesFromConfig(queries map[string][]string, configDi
return nil, fmt.Errorf("no xfconfd found at %s", xfconfdPath)
}

logger.Debug("Using config dir", "XDG_CONFIG_HOME", configDir)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

Expand Down Expand Up @@ -93,12 +97,14 @@ func gatherDefaultPropertyValuesFromConfig(queries map[string][]string, configDi

func gatherDefaultPropertyValues(queries map[string][]string) (map[string]map[string]string, error) {
// Special case to use the test's default values if running end-to-end-test
if _, exists := os.LookupEnv("XFCONF_PANEL_END_TO_END_TEST"); exists {
_, underTest := os.LookupEnv("XFCONF_PROFILE_END_TO_END_TEST")
if underTest {
cwd, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("Cannot get working directory")
}
return gatherDefaultPropertyValuesFromConfig(queries, cwd)
testConfigDir := filepath.Join(cwd, "..", "etc", "xdg")
return gatherDefaultPropertyValuesFromConfig(queries, testConfigDir)
}

configDir := "/usr/etc/xdg"
Expand All @@ -115,3 +121,37 @@ func gatherDefaultPropertyValues(queries map[string][]string) (map[string]map[st

return gatherDefaultPropertyValuesFromConfig(queries, configDir)
}

func gatherCurrentPropertyValues(queries map[string][]string) (map[string]map[string]string, error) {
results := make(map[string]map[string]string)

for channel, properties := range queries {
results[channel] = make(map[string]string)

for _, property := range properties {
cmd := exec.Command("xfconf-query", "--channel", channel, "--property", property)

var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr

err := cmd.Run()

if err != nil {
// If there was an error (property not found)
results[channel][property] = ""
continue
}

// Read the output value
scanner := bufio.NewScanner(&stdout)
if scanner.Scan() {
results[channel][property] = scanner.Text()
} else {
results[channel][property] = ""
}
}
}

return results, nil
}
34 changes: 28 additions & 6 deletions src/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ func applyProfile(profilePath string, mergeBehavior MergeBehavior, exclude Exclu
blue := color.New(color.FgHiBlue).SprintFunc()
yellow := color.New(color.FgHiYellow).SprintFunc()

// Get all the default values
defaultValueQueries := make(map[string][]string)
for channel, properties := range profile {
defaultValueQueries[channel] = []string{}
for property, _ := range properties {
defaultValueQueries[channel] = append(defaultValueQueries[channel], property)
}
}

defaultValues, err := gatherDefaultPropertyValues(defaultValueQueries)
if err != nil {
return fmt.Errorf("could not get default property values: %v", err)
}

currentValues, err := gatherCurrentPropertyValues(defaultValueQueries)
if err != nil {
return fmt.Errorf("could not get current property values: %v", err)
}

for channel, properties := range profile {
// Keys starting with X- are not channels
if strings.HasPrefix(channel, "X-") {
Expand All @@ -39,12 +58,15 @@ func applyProfile(profilePath string, mergeBehavior MergeBehavior, exclude Exclu
for property, value := range properties {
// Check if this property should be skipped based on merge preferences
if mergeBehavior == MergeSoft {
currentValue := "currentValue"
defaultValue := "defaultValue"

if currentValue != defaultValue {
fmt.Printf("%s Skipping property %s with non-default value %s (default=%s)%s\n", yellow("•"), channel, property, currentValue, defaultValue)
continue
defaultValue := defaultValues[channel][property]
currentValue := currentValues[channel][property]

// If there's actually a default and we have an actual current value
if defaultValue != "" && currentValue != "" {
if currentValue != defaultValue {
fmt.Printf("%s Skipping property %s%s with non-default value %s (default=%s)\n", yellow("•"), channel, property, currentValue, defaultValue)
continue
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>

<channel name="xfce4-keyboard-shortcuts" version="1.0">
<property name="commands" type="empty">
<property name="default" type="empty">
<property name="&lt;Alt&gt;F1" type="string" value="xfce4-popup-applicationsmenu"/>
<property name="&lt;Alt&gt;F2" type="string" value="xfce4-appfinder --collapsed">
<property name="startup-notify" type="bool" value="true"/>
</property>
<property name="&lt;Alt&gt;F3" type="string" value="xfce4-appfinder">
<property name="startup-notify" type="bool" value="true"/>
</property>
<property name="XF86LogOff" type="string" value="xfce4-session-logout"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;Delete" type="string" value="xfce4-session-logout"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;l" type="string" value="xflock4"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;t" type="string" value="exo-open --launch TerminalEmulator"/>
<property name="XF86Display" type="string" value="xfce4-display-settings --minimal"/>
<property name="&lt;Super&gt;p" type="string" value="xfce4-display-settings --minimal"/>
<property name="&lt;Primary&gt;Escape" type="string" value="xfdesktop --menu"/>
<property name="XF86WWW" type="string" value="exo-open --launch WebBrowser"/>
<property name="HomePage" type="string" value="exo-open --launch WebBrowser"/>
<property name="XF86Mail" type="string" value="exo-open --launch MailReader"/>
<property name="Print" type="string" value="xfce4-screenshooter"/>
<property name="&lt;Alt&gt;Print" type="string" value="xfce4-screenshooter -w"/>
<property name="&lt;Shift&gt;Print" type="string" value="xfce4-screenshooter -r"/>
<property name="&lt;Super&gt;e" type="string" value="thunar"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;f" type="string" value="thunar"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;Escape" type="string" value="xkill"/>
<property name="&lt;Primary&gt;&lt;Shift&gt;Escape" type="string" value="xfce4-taskmanager"/>
<property name="&lt;Super&gt;r" type="string" value="xfce4-appfinder -c">
<property name="XF86Calendar" type="string" value="orage"/>
<property name="XF86Memo" type="string" value="xfce4-notes"/>
<property name="XF86Terminal" type="string" value="xfce4-terminal"/>
<property name="XF86Explorer" type="string" value="Thunar"/>
<property name="XF86AudioMedia" type="string" value="pragha"/>
<property name="XF86AudioPlay" type="string" value="pragha --pause"/>
<property name="XF86AudioPrev" type="string" value="pragha --prev"/>
<property name="XF86AudioNext" type="string" value="pragha --next"/>
<property name="XF86Calculator" type="string" value="galculator"/>
<property name="startup-notify" type="bool" value="true"/>
</property>
<property name="&lt;Alt&gt;&lt;Super&gt;s" type="string" value="orca"/>
</property>
</property>
<property name="xfwm4" type="empty">
<property name="default" type="empty">
<property name="&lt;Alt&gt;Insert" type="string" value="add_workspace_key"/>
<property name="Escape" type="string" value="cancel_key"/>
<property name="Left" type="string" value="left_key"/>
<property name="Right" type="string" value="right_key"/>
<property name="Up" type="string" value="up_key"/>
<property name="Down" type="string" value="down_key"/>
<property name="&lt;Alt&gt;Tab" type="string" value="cycle_windows_key"/>
<property name="&lt;Alt&gt;&lt;Shift&gt;Tab" type="string" value="cycle_reverse_windows_key"/>
<property name="&lt;Alt&gt;Delete" type="string" value="del_workspace_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;Down" type="string" value="down_workspace_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;Left" type="string" value="left_workspace_key"/>
<property name="&lt;Shift&gt;&lt;Alt&gt;Page_Down" type="string" value="lower_window_key"/>
<property name="&lt;Alt&gt;F4" type="string" value="close_window_key"/>
<property name="&lt;Alt&gt;F6" type="string" value="stick_window_key"/>
<property name="&lt;Alt&gt;F7" type="string" value="move_window_key"/>
<property name="&lt;Alt&gt;F8" type="string" value="resize_window_key"/>
<property name="&lt;Alt&gt;F9" type="string" value="hide_window_key"/>
<property name="&lt;Alt&gt;F10" type="string" value="maximize_window_key"/>
<property name="&lt;Alt&gt;F11" type="string" value="fullscreen_key"/>
<property name="&lt;Alt&gt;F12" type="string" value="above_key"/>
<property name="&lt;Primary&gt;&lt;Shift&gt;&lt;Alt&gt;Left" type="string" value="move_window_left_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;End" type="string" value="move_window_next_workspace_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;Home" type="string" value="move_window_prev_workspace_key"/>
<property name="&lt;Primary&gt;&lt;Shift&gt;&lt;Alt&gt;Right" type="string" value="move_window_right_key"/>
<property name="&lt;Primary&gt;&lt;Shift&gt;&lt;Alt&gt;Up" type="string" value="move_window_up_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_1" type="string" value="move_window_workspace_1_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_2" type="string" value="move_window_workspace_2_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_3" type="string" value="move_window_workspace_3_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_4" type="string" value="move_window_workspace_4_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_5" type="string" value="move_window_workspace_5_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_6" type="string" value="move_window_workspace_6_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_7" type="string" value="move_window_workspace_7_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_8" type="string" value="move_window_workspace_8_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_9" type="string" value="move_window_workspace_9_key"/>
<property name="&lt;Alt&gt;space" type="string" value="popup_menu_key"/>
<property name="&lt;Shift&gt;&lt;Alt&gt;Page_Up" type="string" value="raise_window_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;Right" type="string" value="right_workspace_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;d" type="string" value="show_desktop_key"/>
<property name="&lt;Primary&gt;&lt;Alt&gt;Up" type="string" value="up_workspace_key"/>
<property name="&lt;Super&gt;Tab" type="string" value="switch_window_key"/>
<property name="&lt;Primary&gt;F1" type="string" value="workspace_1_key"/>
<property name="&lt;Primary&gt;F2" type="string" value="workspace_2_key"/>
<property name="&lt;Primary&gt;F3" type="string" value="workspace_3_key"/>
<property name="&lt;Primary&gt;F4" type="string" value="workspace_4_key"/>
<property name="&lt;Primary&gt;F5" type="string" value="workspace_5_key"/>
<property name="&lt;Primary&gt;F6" type="string" value="workspace_6_key"/>
<property name="&lt;Primary&gt;F7" type="string" value="workspace_7_key"/>
<property name="&lt;Primary&gt;F8" type="string" value="workspace_8_key"/>
<property name="&lt;Primary&gt;F9" type="string" value="workspace_9_key"/>
<property name="&lt;Primary&gt;F10" type="string" value="workspace_10_key"/>
<property name="&lt;Primary&gt;F11" type="string" value="workspace_11_key"/>
<property name="&lt;Primary&gt;F12" type="string" value="workspace_12_key"/>
<property name="&lt;Super&gt;KP_Left" type="string" value="tile_left_key"/>
<property name="&lt;Super&gt;KP_Right" type="string" value="tile_right_key"/>
<property name="&lt;Super&gt;KP_Down" type="string" value="tile_down_key"/>
<property name="&lt;Super&gt;KP_Up" type="string" value="tile_up_key"/>
<property name="&lt;Super&gt;KP_Page_Up" type="string" value="tile_up_right_key"/>
<property name="&lt;Super&gt;KP_Home" type="string" value="tile_up_left_key"/>
<property name="&lt;Super&gt;KP_End" type="string" value="tile_down_left_key"/>
<property name="&lt;Super&gt;KP_Next" type="string" value="tile_down_right_key"/>
</property>
</property>
</channel>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<channel name="xfce4-power-manager" version="1.0">
<property name="xfce4-power-manager" type="empty">
<property name="power-button-action" type="uint" value="3"/>
<property name="sleep-button-action" type="uint" value="3"/>
<property name="hibernate-button-action" type="uint" value="3"/>
<property name="show-tray-icon" type="bool" value="true"/>
<property name="logind-handle-lid-switch" type="bool" value="false"/>
</property>
</channel>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>

<channel name="xfce4-session" version="1.0">
<property name="general" type="empty">
<property name="FailsafeSessionName" type="string" value="Failsafe"/>
<property name="LockCommand" type="string" value=""/>
</property>
<property name="sessions" type="empty">
<property name="Failsafe" type="empty">
<property name="IsFailsafe" type="bool" value="true"/>
<property name="Count" type="int" value="5"/>
<property name="Client0_Command" type="array">
<value type="string" value="xfwm4"/>
</property>
<property name="Client0_Priority" type="int" value="15"/>
<property name="Client0_PerScreen" type="bool" value="false"/>
<property name="Client1_Command" type="array">
<value type="string" value="xfsettingsd"/>
</property>
<property name="Client1_Priority" type="int" value="20"/>
<property name="Client1_PerScreen" type="bool" value="false"/>
<property name="Client2_Command" type="array">
<value type="string" value="xfce4-panel"/>
</property>
<property name="Client2_Priority" type="int" value="25"/>
<property name="Client2_PerScreen" type="bool" value="false"/>
<property name="Client3_Command" type="array">
<value type="string" value="Thunar"/>
<value type="string" value="--daemon"/>
</property>
<property name="Client3_Priority" type="int" value="30"/>
<property name="Client3_PerScreen" type="bool" value="false"/>
<property name="Client4_Command" type="array">
<value type="string" value="xfdesktop"/>
</property>
<property name="Client4_Priority" type="int" value="35"/>
<property name="Client4_PerScreen" type="bool" value="false"/>
</property>
</property>
</channel>
52 changes: 52 additions & 0 deletions tests/e2e/etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Default values for the X settings registry as described in
http://www.freedesktop.org/wiki/Specifications/XSettingsRegistry
-->

<channel name="xsettings" version="1.0">
<property name="Net" type="empty">
<property name="ThemeName" type="string" value="Adwaita"/>
<property name="IconThemeName" type="string" value="Adwaita"/>
<property name="DoubleClickTime" type="int" value="400"/>
<property name="DoubleClickDistance" type="int" value="5"/>
<property name="DndDragThreshold" type="int" value="8"/>
<property name="CursorBlink" type="bool" value="true"/>
<property name="CursorBlinkTime" type="int" value="1200"/>
<property name="SoundThemeName" type="string" value="default"/>
<property name="EnableEventSounds" type="bool" value="false"/>
<property name="EnableInputFeedbackSounds" type="bool" value="false"/>
</property>
<property name="Xft" type="empty">
<property name="DPI" type="empty"/>
<property name="Antialias" type="int" value="1"/>
<property name="Hinting" type="int" value="-1"/>
<property name="HintStyle" type="string" value="hintfull"/>
<property name="RGBA" type="string" value="none"/>
<!-- <property name="Lcdfilter" type="string" value="none"/> -->
</property>
<property name="Gtk" type="empty">
<property name="CanChangeAccels" type="bool" value="false"/>
<property name="ColorPalette" type="string" value="black:white:gray50:red:purple:blue:light blue:green:yellow:orange:lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90"/>
<property name="FontName" type="string" value="Sans 10"/>
<property name="MonospaceFontName" type="string" value="Monospace 10"/>
<property name="IconSizes" type="string" value=""/>
<property name="KeyThemeName" type="string" value=""/>
<property name="ToolbarStyle" type="string" value="icons"/>
<property name="ToolbarIconSize" type="int" value="3"/>
<!-- <property name="IMPreeditStyle" type="string" value=""/> -->
<!-- <property name="IMStatusStyle" type="string" value=""/> -->
<!-- <property name="IMModule" type="string" value=""/> -->
<property name="MenuImages" type="bool" value="true"/>
<property name="ButtonImages" type="bool" value="true"/>
<property name="MenuBarAccel" type="string" value="F10"/>
<property name="CursorThemeName" type="string" value=""/>
<property name="CursorThemeSize" type="int" value="0"/>
<property name="DecorationLayout" type="string" value="menu:minimize,maximize,close"/>
<property name="DialogsUseHeader" type="bool" value="false"/>
<property name="TitlebarMiddleClick" type="string" value="lower"/>
</property>
<property name="Gdk" type="empty">
<property name="WindowScalingFactor" type="int" value="1"/>
</property>
</channel>
3 changes: 0 additions & 3 deletions tests/e2e/test-simple/defaults.txt

This file was deleted.

3 changes: 3 additions & 0 deletions tests/e2e/test-simple/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ if ! which xfconf-query | grep -q "/xfconf-profile/"; then
exit 1
fi

export XFCONF_PROFILE_END_TO_END_TEST=1
export LOG_LEVEL=debug

xfconf-profile apply profile.json

if diff expected-log.txt actual-log.txt; then
Expand Down

0 comments on commit 5594647

Please sign in to comment.