Skip to content

Commit 5594647

Browse files
committed
feat: merge behavior should now be fully implemented
1 parent e62834d commit 5594647

File tree

8 files changed

+285
-11
lines changed

8 files changed

+285
-11
lines changed

src/defaults.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package main
22

33
import (
44
"bufio"
5+
"bytes"
56
"context"
67
"fmt"
78
"os"
89
"os/exec"
10+
"path/filepath"
911
"strings"
1012
"time"
1113
)
@@ -23,6 +25,8 @@ func gatherDefaultPropertyValuesFromConfig(queries map[string][]string, configDi
2325
return nil, fmt.Errorf("no xfconfd found at %s", xfconfdPath)
2426
}
2527

28+
logger.Debug("Using config dir", "XDG_CONFIG_HOME", configDir)
29+
2630
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
2731
defer cancel()
2832

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

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

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

116122
return gatherDefaultPropertyValuesFromConfig(queries, configDir)
117123
}
124+
125+
func gatherCurrentPropertyValues(queries map[string][]string) (map[string]map[string]string, error) {
126+
results := make(map[string]map[string]string)
127+
128+
for channel, properties := range queries {
129+
results[channel] = make(map[string]string)
130+
131+
for _, property := range properties {
132+
cmd := exec.Command("xfconf-query", "--channel", channel, "--property", property)
133+
134+
var stdout, stderr bytes.Buffer
135+
cmd.Stdout = &stdout
136+
cmd.Stderr = &stderr
137+
138+
err := cmd.Run()
139+
140+
if err != nil {
141+
// If there was an error (property not found)
142+
results[channel][property] = ""
143+
continue
144+
}
145+
146+
// Read the output value
147+
scanner := bufio.NewScanner(&stdout)
148+
if scanner.Scan() {
149+
results[channel][property] = scanner.Text()
150+
} else {
151+
results[channel][property] = ""
152+
}
153+
}
154+
}
155+
156+
return results, nil
157+
}

src/profile.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ func applyProfile(profilePath string, mergeBehavior MergeBehavior, exclude Exclu
3030
blue := color.New(color.FgHiBlue).SprintFunc()
3131
yellow := color.New(color.FgHiYellow).SprintFunc()
3232

33+
// Get all the default values
34+
defaultValueQueries := make(map[string][]string)
35+
for channel, properties := range profile {
36+
defaultValueQueries[channel] = []string{}
37+
for property, _ := range properties {
38+
defaultValueQueries[channel] = append(defaultValueQueries[channel], property)
39+
}
40+
}
41+
42+
defaultValues, err := gatherDefaultPropertyValues(defaultValueQueries)
43+
if err != nil {
44+
return fmt.Errorf("could not get default property values: %v", err)
45+
}
46+
47+
currentValues, err := gatherCurrentPropertyValues(defaultValueQueries)
48+
if err != nil {
49+
return fmt.Errorf("could not get current property values: %v", err)
50+
}
51+
3352
for channel, properties := range profile {
3453
// Keys starting with X- are not channels
3554
if strings.HasPrefix(channel, "X-") {
@@ -39,12 +58,15 @@ func applyProfile(profilePath string, mergeBehavior MergeBehavior, exclude Exclu
3958
for property, value := range properties {
4059
// Check if this property should be skipped based on merge preferences
4160
if mergeBehavior == MergeSoft {
42-
currentValue := "currentValue"
43-
defaultValue := "defaultValue"
44-
45-
if currentValue != defaultValue {
46-
fmt.Printf("%s Skipping property %s with non-default value %s (default=%s)%s\n", yellow("•"), channel, property, currentValue, defaultValue)
47-
continue
61+
defaultValue := defaultValues[channel][property]
62+
currentValue := currentValues[channel][property]
63+
64+
// If there's actually a default and we have an actual current value
65+
if defaultValue != "" && currentValue != "" {
66+
if currentValue != defaultValue {
67+
fmt.Printf("%s Skipping property %s%s with non-default value %s (default=%s)\n", yellow("•"), channel, property, currentValue, defaultValue)
68+
continue
69+
}
4870
}
4971
}
5072

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<channel name="xfce4-keyboard-shortcuts" version="1.0">
4+
<property name="commands" type="empty">
5+
<property name="default" type="empty">
6+
<property name="&lt;Alt&gt;F1" type="string" value="xfce4-popup-applicationsmenu"/>
7+
<property name="&lt;Alt&gt;F2" type="string" value="xfce4-appfinder --collapsed">
8+
<property name="startup-notify" type="bool" value="true"/>
9+
</property>
10+
<property name="&lt;Alt&gt;F3" type="string" value="xfce4-appfinder">
11+
<property name="startup-notify" type="bool" value="true"/>
12+
</property>
13+
<property name="XF86LogOff" type="string" value="xfce4-session-logout"/>
14+
<property name="&lt;Primary&gt;&lt;Alt&gt;Delete" type="string" value="xfce4-session-logout"/>
15+
<property name="&lt;Primary&gt;&lt;Alt&gt;l" type="string" value="xflock4"/>
16+
<property name="&lt;Primary&gt;&lt;Alt&gt;t" type="string" value="exo-open --launch TerminalEmulator"/>
17+
<property name="XF86Display" type="string" value="xfce4-display-settings --minimal"/>
18+
<property name="&lt;Super&gt;p" type="string" value="xfce4-display-settings --minimal"/>
19+
<property name="&lt;Primary&gt;Escape" type="string" value="xfdesktop --menu"/>
20+
<property name="XF86WWW" type="string" value="exo-open --launch WebBrowser"/>
21+
<property name="HomePage" type="string" value="exo-open --launch WebBrowser"/>
22+
<property name="XF86Mail" type="string" value="exo-open --launch MailReader"/>
23+
<property name="Print" type="string" value="xfce4-screenshooter"/>
24+
<property name="&lt;Alt&gt;Print" type="string" value="xfce4-screenshooter -w"/>
25+
<property name="&lt;Shift&gt;Print" type="string" value="xfce4-screenshooter -r"/>
26+
<property name="&lt;Super&gt;e" type="string" value="thunar"/>
27+
<property name="&lt;Primary&gt;&lt;Alt&gt;f" type="string" value="thunar"/>
28+
<property name="&lt;Primary&gt;&lt;Alt&gt;Escape" type="string" value="xkill"/>
29+
<property name="&lt;Primary&gt;&lt;Shift&gt;Escape" type="string" value="xfce4-taskmanager"/>
30+
<property name="&lt;Super&gt;r" type="string" value="xfce4-appfinder -c">
31+
<property name="XF86Calendar" type="string" value="orage"/>
32+
<property name="XF86Memo" type="string" value="xfce4-notes"/>
33+
<property name="XF86Terminal" type="string" value="xfce4-terminal"/>
34+
<property name="XF86Explorer" type="string" value="Thunar"/>
35+
<property name="XF86AudioMedia" type="string" value="pragha"/>
36+
<property name="XF86AudioPlay" type="string" value="pragha --pause"/>
37+
<property name="XF86AudioPrev" type="string" value="pragha --prev"/>
38+
<property name="XF86AudioNext" type="string" value="pragha --next"/>
39+
<property name="XF86Calculator" type="string" value="galculator"/>
40+
<property name="startup-notify" type="bool" value="true"/>
41+
</property>
42+
<property name="&lt;Alt&gt;&lt;Super&gt;s" type="string" value="orca"/>
43+
</property>
44+
</property>
45+
<property name="xfwm4" type="empty">
46+
<property name="default" type="empty">
47+
<property name="&lt;Alt&gt;Insert" type="string" value="add_workspace_key"/>
48+
<property name="Escape" type="string" value="cancel_key"/>
49+
<property name="Left" type="string" value="left_key"/>
50+
<property name="Right" type="string" value="right_key"/>
51+
<property name="Up" type="string" value="up_key"/>
52+
<property name="Down" type="string" value="down_key"/>
53+
<property name="&lt;Alt&gt;Tab" type="string" value="cycle_windows_key"/>
54+
<property name="&lt;Alt&gt;&lt;Shift&gt;Tab" type="string" value="cycle_reverse_windows_key"/>
55+
<property name="&lt;Alt&gt;Delete" type="string" value="del_workspace_key"/>
56+
<property name="&lt;Primary&gt;&lt;Alt&gt;Down" type="string" value="down_workspace_key"/>
57+
<property name="&lt;Primary&gt;&lt;Alt&gt;Left" type="string" value="left_workspace_key"/>
58+
<property name="&lt;Shift&gt;&lt;Alt&gt;Page_Down" type="string" value="lower_window_key"/>
59+
<property name="&lt;Alt&gt;F4" type="string" value="close_window_key"/>
60+
<property name="&lt;Alt&gt;F6" type="string" value="stick_window_key"/>
61+
<property name="&lt;Alt&gt;F7" type="string" value="move_window_key"/>
62+
<property name="&lt;Alt&gt;F8" type="string" value="resize_window_key"/>
63+
<property name="&lt;Alt&gt;F9" type="string" value="hide_window_key"/>
64+
<property name="&lt;Alt&gt;F10" type="string" value="maximize_window_key"/>
65+
<property name="&lt;Alt&gt;F11" type="string" value="fullscreen_key"/>
66+
<property name="&lt;Alt&gt;F12" type="string" value="above_key"/>
67+
<property name="&lt;Primary&gt;&lt;Shift&gt;&lt;Alt&gt;Left" type="string" value="move_window_left_key"/>
68+
<property name="&lt;Primary&gt;&lt;Alt&gt;End" type="string" value="move_window_next_workspace_key"/>
69+
<property name="&lt;Primary&gt;&lt;Alt&gt;Home" type="string" value="move_window_prev_workspace_key"/>
70+
<property name="&lt;Primary&gt;&lt;Shift&gt;&lt;Alt&gt;Right" type="string" value="move_window_right_key"/>
71+
<property name="&lt;Primary&gt;&lt;Shift&gt;&lt;Alt&gt;Up" type="string" value="move_window_up_key"/>
72+
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_1" type="string" value="move_window_workspace_1_key"/>
73+
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_2" type="string" value="move_window_workspace_2_key"/>
74+
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_3" type="string" value="move_window_workspace_3_key"/>
75+
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_4" type="string" value="move_window_workspace_4_key"/>
76+
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_5" type="string" value="move_window_workspace_5_key"/>
77+
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_6" type="string" value="move_window_workspace_6_key"/>
78+
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_7" type="string" value="move_window_workspace_7_key"/>
79+
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_8" type="string" value="move_window_workspace_8_key"/>
80+
<property name="&lt;Primary&gt;&lt;Alt&gt;KP_9" type="string" value="move_window_workspace_9_key"/>
81+
<property name="&lt;Alt&gt;space" type="string" value="popup_menu_key"/>
82+
<property name="&lt;Shift&gt;&lt;Alt&gt;Page_Up" type="string" value="raise_window_key"/>
83+
<property name="&lt;Primary&gt;&lt;Alt&gt;Right" type="string" value="right_workspace_key"/>
84+
<property name="&lt;Primary&gt;&lt;Alt&gt;d" type="string" value="show_desktop_key"/>
85+
<property name="&lt;Primary&gt;&lt;Alt&gt;Up" type="string" value="up_workspace_key"/>
86+
<property name="&lt;Super&gt;Tab" type="string" value="switch_window_key"/>
87+
<property name="&lt;Primary&gt;F1" type="string" value="workspace_1_key"/>
88+
<property name="&lt;Primary&gt;F2" type="string" value="workspace_2_key"/>
89+
<property name="&lt;Primary&gt;F3" type="string" value="workspace_3_key"/>
90+
<property name="&lt;Primary&gt;F4" type="string" value="workspace_4_key"/>
91+
<property name="&lt;Primary&gt;F5" type="string" value="workspace_5_key"/>
92+
<property name="&lt;Primary&gt;F6" type="string" value="workspace_6_key"/>
93+
<property name="&lt;Primary&gt;F7" type="string" value="workspace_7_key"/>
94+
<property name="&lt;Primary&gt;F8" type="string" value="workspace_8_key"/>
95+
<property name="&lt;Primary&gt;F9" type="string" value="workspace_9_key"/>
96+
<property name="&lt;Primary&gt;F10" type="string" value="workspace_10_key"/>
97+
<property name="&lt;Primary&gt;F11" type="string" value="workspace_11_key"/>
98+
<property name="&lt;Primary&gt;F12" type="string" value="workspace_12_key"/>
99+
<property name="&lt;Super&gt;KP_Left" type="string" value="tile_left_key"/>
100+
<property name="&lt;Super&gt;KP_Right" type="string" value="tile_right_key"/>
101+
<property name="&lt;Super&gt;KP_Down" type="string" value="tile_down_key"/>
102+
<property name="&lt;Super&gt;KP_Up" type="string" value="tile_up_key"/>
103+
<property name="&lt;Super&gt;KP_Page_Up" type="string" value="tile_up_right_key"/>
104+
<property name="&lt;Super&gt;KP_Home" type="string" value="tile_up_left_key"/>
105+
<property name="&lt;Super&gt;KP_End" type="string" value="tile_down_left_key"/>
106+
<property name="&lt;Super&gt;KP_Next" type="string" value="tile_down_right_key"/>
107+
</property>
108+
</property>
109+
</channel>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<channel name="xfce4-power-manager" version="1.0">
4+
<property name="xfce4-power-manager" type="empty">
5+
<property name="power-button-action" type="uint" value="3"/>
6+
<property name="sleep-button-action" type="uint" value="3"/>
7+
<property name="hibernate-button-action" type="uint" value="3"/>
8+
<property name="show-tray-icon" type="bool" value="true"/>
9+
<property name="logind-handle-lid-switch" type="bool" value="false"/>
10+
</property>
11+
</channel>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<channel name="xfce4-session" version="1.0">
4+
<property name="general" type="empty">
5+
<property name="FailsafeSessionName" type="string" value="Failsafe"/>
6+
<property name="LockCommand" type="string" value=""/>
7+
</property>
8+
<property name="sessions" type="empty">
9+
<property name="Failsafe" type="empty">
10+
<property name="IsFailsafe" type="bool" value="true"/>
11+
<property name="Count" type="int" value="5"/>
12+
<property name="Client0_Command" type="array">
13+
<value type="string" value="xfwm4"/>
14+
</property>
15+
<property name="Client0_Priority" type="int" value="15"/>
16+
<property name="Client0_PerScreen" type="bool" value="false"/>
17+
<property name="Client1_Command" type="array">
18+
<value type="string" value="xfsettingsd"/>
19+
</property>
20+
<property name="Client1_Priority" type="int" value="20"/>
21+
<property name="Client1_PerScreen" type="bool" value="false"/>
22+
<property name="Client2_Command" type="array">
23+
<value type="string" value="xfce4-panel"/>
24+
</property>
25+
<property name="Client2_Priority" type="int" value="25"/>
26+
<property name="Client2_PerScreen" type="bool" value="false"/>
27+
<property name="Client3_Command" type="array">
28+
<value type="string" value="Thunar"/>
29+
<value type="string" value="--daemon"/>
30+
</property>
31+
<property name="Client3_Priority" type="int" value="30"/>
32+
<property name="Client3_PerScreen" type="bool" value="false"/>
33+
<property name="Client4_Command" type="array">
34+
<value type="string" value="xfdesktop"/>
35+
</property>
36+
<property name="Client4_Priority" type="int" value="35"/>
37+
<property name="Client4_PerScreen" type="bool" value="false"/>
38+
</property>
39+
</property>
40+
</channel>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Default values for the X settings registry as described in
4+
http://www.freedesktop.org/wiki/Specifications/XSettingsRegistry
5+
-->
6+
7+
<channel name="xsettings" version="1.0">
8+
<property name="Net" type="empty">
9+
<property name="ThemeName" type="string" value="Adwaita"/>
10+
<property name="IconThemeName" type="string" value="Adwaita"/>
11+
<property name="DoubleClickTime" type="int" value="400"/>
12+
<property name="DoubleClickDistance" type="int" value="5"/>
13+
<property name="DndDragThreshold" type="int" value="8"/>
14+
<property name="CursorBlink" type="bool" value="true"/>
15+
<property name="CursorBlinkTime" type="int" value="1200"/>
16+
<property name="SoundThemeName" type="string" value="default"/>
17+
<property name="EnableEventSounds" type="bool" value="false"/>
18+
<property name="EnableInputFeedbackSounds" type="bool" value="false"/>
19+
</property>
20+
<property name="Xft" type="empty">
21+
<property name="DPI" type="empty"/>
22+
<property name="Antialias" type="int" value="1"/>
23+
<property name="Hinting" type="int" value="-1"/>
24+
<property name="HintStyle" type="string" value="hintfull"/>
25+
<property name="RGBA" type="string" value="none"/>
26+
<!-- <property name="Lcdfilter" type="string" value="none"/> -->
27+
</property>
28+
<property name="Gtk" type="empty">
29+
<property name="CanChangeAccels" type="bool" value="false"/>
30+
<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"/>
31+
<property name="FontName" type="string" value="Sans 10"/>
32+
<property name="MonospaceFontName" type="string" value="Monospace 10"/>
33+
<property name="IconSizes" type="string" value=""/>
34+
<property name="KeyThemeName" type="string" value=""/>
35+
<property name="ToolbarStyle" type="string" value="icons"/>
36+
<property name="ToolbarIconSize" type="int" value="3"/>
37+
<!-- <property name="IMPreeditStyle" type="string" value=""/> -->
38+
<!-- <property name="IMStatusStyle" type="string" value=""/> -->
39+
<!-- <property name="IMModule" type="string" value=""/> -->
40+
<property name="MenuImages" type="bool" value="true"/>
41+
<property name="ButtonImages" type="bool" value="true"/>
42+
<property name="MenuBarAccel" type="string" value="F10"/>
43+
<property name="CursorThemeName" type="string" value=""/>
44+
<property name="CursorThemeSize" type="int" value="0"/>
45+
<property name="DecorationLayout" type="string" value="menu:minimize,maximize,close"/>
46+
<property name="DialogsUseHeader" type="bool" value="false"/>
47+
<property name="TitlebarMiddleClick" type="string" value="lower"/>
48+
</property>
49+
<property name="Gdk" type="empty">
50+
<property name="WindowScalingFactor" type="int" value="1"/>
51+
</property>
52+
</channel>

tests/e2e/test-simple/defaults.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/e2e/test-simple/driver.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ if ! which xfconf-query | grep -q "/xfconf-profile/"; then
99
exit 1
1010
fi
1111

12+
export XFCONF_PROFILE_END_TO_END_TEST=1
13+
export LOG_LEVEL=debug
14+
1215
xfconf-profile apply profile.json
1316

1417
if diff expected-log.txt actual-log.txt; then

0 commit comments

Comments
 (0)