DEV Community

Puneet Khandelwal
Puneet Khandelwal

Posted on

When Your Screen Becomes a Habit: A Waybar Widget to Hard‑Cut Time

Desk‑bound hours hit me when the screen was the only thing keeping me awake. I flipped that around by making the screen punish the habit. I built a Waybar widget that tracks daily usage and forces hard context switches.

The widget polls the window manager for focus changes, aggregates how long each app stays active, and when a threshold is crossed, it drops a modal overlay that blocks the screen for a set interval. The overlay is a tiny X11 window that covers the monitor and needs a key press to go away. In my setup, the threshold is 90 minutes of continuous use in any single application.

I rely on a few familiar tools. xdotool grabs the active window title every five seconds and logs the timestamp. A small SQLite database keeps a rolling 24‑hour window. When the widget starts, it reads that data, sums the time per app, and shows a compact bar chart in Waybar.

When an app hits 90 minutes, the widget spawns the overlay. The overlay is a minimal X11 client written in Python with tkinter. It draws a translucent gray rectangle over the screen, shows a countdown, and requires the user to press “Esc” or click a button to dismiss. If they don't, the overlay sticks around until they do, so the context switch isn’t just a trick.

Enforcement vs. usability is a trade‑off. Some devs say blocking the screen is too harsh. I found a 30‑second countdown gives enough time to notice the habit and mentally switch tasks. The overlay stays low‑impact: muted color, no flashing, a gentle sound cue. That keeps the interruption from becoming a new annoyance.

Privacy matters too. The widget logs only window titles, not content. The database lives in the user’s home folder with restrictive permissions, so no external service sees it. That satisfies most developers worried about third‑party trackers.

Here’s the core snippet that launches the overlay:

import tkinter as tk

def block_screen(duration):
 root = tk.Tk()
 root.attributes('-fullscreen', True)
 root.attributes('-topmost', True)
 root.configure(background='gray')
 root.attributes('-alpha', 0.7)
 tk.Label(root, text=f"Time to take a break. {duration}s left.", font=('Helvetica', 24)).pack(expand=True)
 root.bind('<Escape>', lambda e: root.destroy())
 root.after(duration * 1000, root.destroy)
 root.mainloop()
⭐ Must Read: puneet khandelwal ae/when your screen becomes a habit a waybar widget to hard cut time o - Kapook Update 2025 ⭐ Must Read: puneet khandelwal ae/when your screen becomes a habit a waybar widget to hard cut time o - Kapook Update 2025

When the threshold hits, the Waybar script calls block_screen(30). The 30‑second window breaks momentum but lets a dev jump back in without feeling punished.

After a month of using the widget, my average continuous session fell from 120 minutes to 70 minutes. I also saw a spike in distinct applications per day, meaning more purposeful switching.

Next, I’ll expose the widget’s configuration through Waybar’s JSON schema. That lets teams standardise thresholds and overlay styles, turning a personal hack into a shared policy. It also opens the door to analytics: aggregating data across a team could reveal hidden bottlenecks, like an IDE that hogs too much time.

Most dev teams don’t lack tools; they lack hard limits that feel fair. By giving the screen itself the authority to enforce breaks, we turn a passive habit into an active decision point. The widget is small, but it reminds us that in a world of infinite scrolling, the only thing that matters is how we choose to look away.

Top comments (0)