Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit 036d71b

Browse files
author
Tuxx
committed
refactor: simplify configuration and remove unused features
- General - Remove idle monitoring implementation from X11 and Wayland lockers - Configuration - Remove unused configuration options - BackgroundColor (not used in rendering) - BlurBackground (incomplete functionality) - IdleTimeout (removed idle monitoring) - MediaPlayerCmd (hardcoded to mpv) - Added (disabled by default) - lock_pause_media (Pause any playing media via d-bus) - unlock_unpause_media (Unpause any playing media via d-bus) - Media Control - Added the option to pause/unpause any playing media when locking/unlocking the screen. - Simplify media control: - Hardcode mpv as the media player - Remove MediaPlayerCmd configuration option This change makes the codebase more focused and maintainable by removing unused features while preserving core functionality.
1 parent 6183ce0 commit 036d71b

File tree

10 files changed

+766
-789
lines changed

10 files changed

+766
-789
lines changed

README.md

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,14 @@ mkdir -p ~/.config/fancylock
4747
cat > ~/.config/fancylock/config.json << 'EOF'
4848
{
4949
"media_dir": "$HOME/Videos",
50-
"lock_screen": false,
5150
"supported_extensions": [".mp4", ".mkv", ".mov", ".avi", ".webm"],
5251
"pam_service": "fancylock",
5352
"include_images": true,
5453
"image_display_time": 30,
55-
"background_color": "#000000",
56-
"blur_background": false,
57-
"media_player_cmd": "mpv",
5854
"pre_lock_command": "",
59-
"post_lock_command": ""
55+
"post_lock_command": "",
56+
"lock_pause_media": false,
57+
"unlock_unpause_media": false
6058
}
6159
EOF
6260
```
@@ -182,33 +180,29 @@ fancylock -c /path/to/config.json
182180
```json
183181
{
184182
"media_dir": "/home/user/Videos",
185-
"lock_screen": false,
186183
"supported_extensions": [".mp4", ".mkv", ".mov", ".avi", ".webm"],
187184
"pam_service": "fancylock",
188185
"include_images": true,
189186
"image_display_time": 30,
190-
"background_color": "#000000",
191-
"blur_background": false,
192-
"media_player_cmd": "mpv",
193187
"pre_lock_command": "pypr hide mywindow",
194-
"post_lock_command": "pypr show mywindow"
188+
"post_lock_command": "pypr show mywindow",
189+
"lock_pause_media": false,
190+
"unlock_unpause_media": false
195191
}
196192
```
197193
</details>
198194

199195
### Configuration Options
200196

201197
- `media_dir`: Directory containing videos/images to display while locked
202-
- `lock_screen`: Whether to lock the screen immediately on startup
203198
- `supported_extensions`: File extensions to look for in the media directory
204199
- `pam_service`: PAM service name for authentication
205200
- `include_images`: Whether to include images along with videos
206201
- `image_display_time`: How long to display each image in seconds
207-
- `media_player_cmd`: Command to use for playing media (default: mpv)
208-
- `pre_lock_command`: Execute this command before locking the screen.
209-
- `post_lock_command`: Execute this command after unlocking the screen.
210-
211-
Note: The configuration also includes `background_color` and `blur_background` options, but these are not currently implemented.
202+
- `pre_lock_command`: Execute this command before locking the screen
203+
- `post_lock_command`: Execute this command after unlocking the screen
204+
- `lock_pause_media`: Whether to pause all media players when locking the screen
205+
- `unlock_unpause_media`: Whether to unpause all media players when unlocking the screen
212206

213207
## Current Status
214208

@@ -222,25 +216,21 @@ Note: The configuration also includes `background_color` and `blur_background` o
222216
- ✅ Keyboard and pointer grabbing to prevent bypass
223217
- ✅ Failed password attempt limiting
224218
- ✅ Embedded version metadata via `-v`
219+
- ✅ MPRIS media control (pause/unpause)
225220

226221
### What Needs Improvement
227222

228223
- ⚠️ Error handling in some edge cases
229-
- ⚠️ Password entry UI could be more polished
230224
- ⚠️ Memory optimization for long-running sessions
231225
- ⚠️ Better handling of system sleep/wake events
232226
- ⚠️ Auto-creation of default config file (if none exists)
233227

234228
## Future Implementations
235229

230+
- 🚧 Clock display in center of the screen
236231
- 🚧 Configurable UI theme and appearance
237-
- 🚧 Blurred background option
238232
- 🚧 More interactive lock screen elements
239-
- 🚧 Support for additional media players
240-
- 🚧 Screensaver mode with clock display
241-
- 🚧 Improved multi-head support (different videos per monitor)
242233
- 🚧 Systemd integration
243-
- 🚧 Implementation of background color and blur options
244234
- 🚧 Auto-generation of default config file
245235

246236
## Developer Setup

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.24.0
44

55
require (
66
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc
7+
github.com/godbus/dbus/v5 v5.1.0
78
github.com/msteinert/pam v1.2.0
89
github.com/neurlang/wayland v0.2.1
910
github.com/tuxx/wayland-ext-session-lock-go v0.0.0-20250328013740-430eff7f7869

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc h1:7D+Bh06CRPCJO3gr2F7h1sriovOZ8BMhca2Rg85c2nk=
22
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
3+
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
4+
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
35
github.com/msteinert/pam v1.2.0 h1:mYfjlvN2KYs2Pb9G6nb/1f/nPfAttT/Jee5Sq9r3bGE=
46
github.com/msteinert/pam v1.2.0/go.mod h1:d2n0DCUK8rGecChV3JzvmsDjOY4R7AYbsNxAT+ftQl0=
57
github.com/neurlang/wayland v0.2.1 h1:/krK1Flt6VMCj/+KgEYhbm27fkYYEDGkiF1IzNlO43E=

internal/config.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@ func DefaultConfig() Configuration {
2121
}
2222

2323
return Configuration{
24-
MediaDir: filepath.Join(homeDir, "Videos"),
25-
LockScreen: false,
26-
SupportedExt: []string{".mov", ".mkv", ".mp4", ".avi", ".webm"},
27-
IdleTimeout: 300, // 5 minutes
28-
PamService: PamService,
29-
IncludeImages: true,
30-
ImageDisplayTime: 30,
31-
BackgroundColor: "#000000",
32-
BlurBackground: false,
33-
MediaPlayerCmd: "mpv",
34-
DebugExit: false, // Disabled by default for security
35-
PreLockCommand: "", // No default pre-lock command
36-
PostLockCommand: "", // No default post-lock command
24+
MediaDir: filepath.Join(homeDir, "Videos"),
25+
LockScreen: false,
26+
SupportedExt: []string{".mov", ".mkv", ".mp4", ".avi", ".webm"},
27+
PamService: PamService,
28+
IncludeImages: true,
29+
ImageDisplayTime: 30,
30+
DebugExit: false, // Disabled by default for security
31+
PreLockCommand: "", // No default pre-lock command
32+
PostLockCommand: "", // No default post-lock command
33+
LockPauseMedia: false, // Disabled by default
34+
UnlockUnpauseMedia: false, // Disabled by default
3735
}
3836
}
3937

@@ -102,11 +100,6 @@ func validateConfig(config *Configuration) error {
102100
return fmt.Errorf("no supported media extensions specified")
103101
}
104102

105-
// Ensure idle timeout is reasonable
106-
if config.IdleTimeout < 0 {
107-
return fmt.Errorf("idle timeout cannot be negative")
108-
}
109-
110103
// Ensure image display time is reasonable
111104
if config.ImageDisplayTime <= 0 {
112105
return fmt.Errorf("image display time must be positive")

internal/lock.go

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ func (a *PamAuthenticator) Authenticate(password string) AuthResult {
8787
}
8888
}
8989

90+
// LockHelper handles screen locking operations
9091
type LockHelper struct {
9192
authenticator *PamAuthenticator
9293
config Configuration
94+
mediaCtrl *MediaController
9395
}
9496

9597
// NewLockHelper creates a new helper instance with the given configuration
@@ -99,9 +101,25 @@ func NewLockHelper(config Configuration) *LockHelper {
99101
username: os.Getenv("USER"),
100102
}
101103

104+
var mediaCtrl *MediaController
105+
if config.LockPauseMedia || config.UnlockUnpauseMedia {
106+
Debug("Media control is enabled, initializing media controller")
107+
var err error
108+
mediaCtrl, err = NewMediaController()
109+
if err != nil {
110+
// Log error but continue without media control
111+
Error("Failed to initialize media controller: %v", err)
112+
} else {
113+
Debug("Media controller initialized successfully")
114+
}
115+
} else {
116+
Debug("Media control is disabled, skipping media controller initialization")
117+
}
118+
102119
return &LockHelper{
103120
authenticator: auth,
104121
config: config,
122+
mediaCtrl: mediaCtrl,
105123
}
106124
}
107125

@@ -167,18 +185,6 @@ func (h *LockHelper) DisableVTs() func() {
167185
}
168186
}
169187

170-
// BlurBackground blurs the screen contents if enabled in config
171-
func (h *LockHelper) BlurBackground() ([]byte, error) {
172-
if !h.config.BlurBackground {
173-
return nil, nil
174-
}
175-
176-
// This would typically capture the screen and apply a blur
177-
// Returns the blurred screenshot data
178-
179-
return nil, nil
180-
}
181-
182188
// EnsureSingleInstance makes sure only one instance of the locker is running
183189
func (h *LockHelper) EnsureSingleInstance() error {
184190
// Try to get an exclusive lock on a file
@@ -266,3 +272,42 @@ func (p *SecurePassword) Length() int {
266272
func runShellCommand(cmd string) error {
267273
return exec.Command("sh", "-c", strings.TrimSpace(cmd)).Run()
268274
}
275+
276+
// PauseMediaIfEnabled pauses all media if enabled in config
277+
func (h *LockHelper) PauseMediaIfEnabled() error {
278+
if !h.config.LockPauseMedia {
279+
Debug("LockPauseMedia is disabled in config, skipping media pause")
280+
return nil
281+
}
282+
283+
if h.mediaCtrl == nil {
284+
Error("LockPauseMedia is enabled but media controller is not initialized")
285+
return nil
286+
}
287+
288+
Debug("Pausing all media players")
289+
return h.mediaCtrl.PauseAllMedia()
290+
}
291+
292+
// UnpauseMediaIfEnabled unpauses all media if enabled in config
293+
func (h *LockHelper) UnpauseMediaIfEnabled() error {
294+
if !h.config.UnlockUnpauseMedia {
295+
Debug("UnlockUnpauseMedia is disabled in config, skipping media unpause")
296+
return nil
297+
}
298+
299+
if h.mediaCtrl == nil {
300+
Error("UnlockUnpauseMedia is enabled but media controller is not initialized")
301+
return nil
302+
}
303+
304+
Debug("Unpausing all media players")
305+
return h.mediaCtrl.UnpauseAllMedia()
306+
}
307+
308+
// Close cleans up resources
309+
func (h *LockHelper) Close() {
310+
if h.mediaCtrl != nil {
311+
h.mediaCtrl.Close()
312+
}
313+
}

internal/media.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,12 @@ func (mp *MediaPlayer) startPlaylistOnMonitor(monitor Monitor, monitorIdx int) e
179179
geometry := fmt.Sprintf("%dx%d+%d+%d", monitor.Width, monitor.Height, monitor.X, monitor.Y)
180180

181181
// Create mpv command with playlist
182-
playerCmd := mp.config.MediaPlayerCmd
183-
if playerCmd == "" {
184-
playerCmd = "mpv"
185-
}
186-
187182
// Add a new option to get mpv to report the current file
188183
// This will help us track what's playing on each monitor
189184
ipcSocketPath := fmt.Sprintf("/tmp/fancylock-mpv-socket-%d", monitorIdx)
190185
os.Remove(ipcSocketPath) // Remove any existing socket
191186

192-
cmd := exec.Command(playerCmd,
187+
cmd := exec.Command("mpv",
193188
"--no-input-default-bindings", // Disable default key bindings
194189
"--really-quiet", // No console output
195190
"--no-stop-screensaver", // Don't interfere with screensaver

0 commit comments

Comments
 (0)