Skip to content

fix(weather): support multiple widget instances - #490

Open
madhur wants to merge 4 commits into
streetturtle:masterfrom
madhur:fix/weather-widget-multiple-instances
Open

fix(weather): support multiple widget instances#490
madhur wants to merge 4 commits into
streetturtle:masterfrom
madhur:fix/weather-widget-multiple-instances

Conversation

@madhur

@madhur madhur commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes an issue where multiple weather widget instances share the same popup and highlight state, causing incorrect behavior.

Problem:
When using multiple weather widgets (e.g., for different cities), the following issues occur:

  • Clicking one widget opens another widget's popup (showing wrong city's weather)
  • Clicking one widget highlights another widget in the taskbar

Root Cause:
weather_popup and weather_widget were defined at module level, so all widget instances created by calling weather_widget({...}) shared the same popup and widget reference.

Fix:
Move weather_popup and weather_widget declarations inside the worker() function, ensuring each widget instance has its own isolated state.

Test plan

  • Create two weather widgets with different coordinates
  • Verify clicking each widget opens its own popup with correct weather data
  • Verify clicking each widget only highlights that specific widget in the bar

🤖 Generated with Claude Code

Previously, weather_popup and weather_widget were defined at module level,
causing all widget instances to share the same popup and highlight state.
This resulted in incorrect behavior when using multiple weather widgets
(e.g., for different cities):
- Clicking one widget would show another widget's popup
- Clicking one widget would highlight another widget in the bar

This fix moves weather_popup and weather_widget inside the worker() function,
ensuring each widget instance has its own isolated state.
@madhur
madhur requested a review from utix as a code owner January 27, 2026 16:16
madhur and others added 2 commits January 27, 2026 21:54
Rename `weather_widget` to `widget` inside worker() to avoid
shadowing the module-level `weather_widget` variable on line 43.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Rename `widget` parameter to `w` in update_widget() to avoid
shadowing the outer `widget` variable on line 169.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@Ryuno-Ki Ryuno-Ki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I can see only some renames and a move of some codeblock I vote for rejecting it.
As expected, LLMs like Claude produce low-quality PRs.

local ICONS_DIR = WIDGET_DIR .. '/icons/' .. icon_pack_name .. '/'

-- Create popup per widget instance to support multiple weather widgets
local weather_popup = awful.popup {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this moved down?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the goal is to create several popup instead of only one.
This is the real need, this move create scope issue and trigger other renaming.
The renaming is bad, for me this should be improved not rejected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been improved @utix

Comment thread weather-widget/weather.lua Outdated
}

local function update_widget(widget, stdout, stderr)
local function update_widget(w, stdout, stderr)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the variable renamed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is actually an improvement over the actual code.

Renaming the variable here prevents shadowing from the local widget variable from line 169. Making the widget line 169 local makes the main worker function a real constructor/factory/builder that creates new instances of the widget instead of using one shared (that gets overwritten by multiple call of the worker?).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, correct

@madhur

madhur commented Jan 28, 2026 via email

Copy link
Copy Markdown
Contributor Author

Rename parameter 'w' to 'weather_icon' for better readability.
This addresses review feedback about unclear variable naming while
maintaining the fix for variable shadowing with the outer 'widget'.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@madhur
madhur requested a review from Ryuno-Ki January 28, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants