Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: module/ipc: The literal '%output%' is displayed until output is received or the command terminates (initial hook only) #3131

Closed
5 tasks done
SeerLite opened this issue Jun 19, 2024 · 4 comments

Comments

@SeerLite
Copy link

SeerLite commented Jun 19, 2024

Checklist

  • I have read the appropriate section in the contributing guidelines
  • I believe this issue is a problem with polybar itself and not a misconfiguration on my part
  • I have searched for other open and closed issues that may have already reported this problem
  • I have checked the known issues page for this problem.
  • I have followed the debugging guide to narrow down the problem to a minimal config.

Steps to reproduce

  1. polybar example
  2. See how %output% is displayed until 5 seconds pass

Minimal config

[bar/example]
modules-left = ipc_output
enable-ipc = true

[module/ipc_output]
type = custom/ipc
hook-0 = sleep 5; echo
initial = 1

Polybar log

notice: Parsing config file: /tmp/.psub.JkUPb1Tm6m
- config_parser: Parsing /tmp/.psub.JkUPb1Tm6m
* Created legacy ipc fifo at '/tmp/polybar_mqueue.26195'
* Opening ipc socket at '/run/user/1000/polybar/ipc.26195.sock'
notice: Listening for IPC messages (PID: 26195)
* Loaded monitor eDP-1 (1920x1080 0 0)
* Configured DPI = 96x96
* Bar geometry: 1920x24 0 0; Borders: 0,0,0,0
- bar: Attach X event sink
- bar: Attach signal receiver
- controller: Setup user-defined modules
notice: Loading module 'ipc_output' of type 'custom/ipc'
* module/ipc_output: Loaded 1 hooks
notice: Loaded 1 modules
* Starting application
- controller: Main thread id = 1
* Entering event loop (thread-id=1)
- bar: Create renderer
- renderer: Get TrueColor visual
* renderer: Using 32-bit TrueColor visual: 0xab
- renderer: Allocate colormap
- renderer: Allocate output window
- renderer: Allocate window pixmaps
- renderer: Allocate graphic contexts
- renderer: Allocate alignment blocks
- renderer: Allocate cairo components
- renderer: Load fonts
warn: No fonts specified, using fallback font "fixed"
notice: Loaded font "fixed" (name=Fixed, offset=0, file=/nix/store/bsv3xk17x3hld3qqzrs8jjf8kffbjbw3-font-misc-misc-1.1.3/lib/X11/fonts/misc/7x13-ISO8859-1.pcf.gz)
* Bar window: 0x7800001
- bar: Reconfigure window
- bar: Set window WM_NAME
- bar: Set window _NET_WM_WINDOW_TYPE
- bar: Set window _NET_WM_STATE
- bar: Set window _NET_WM_DESKTOP
- bar: Set window _NET_WM_PID
- bar: Map window
- background_manager: update_geometry
- background_manager: deactivating because there are no slices to observe
- bar: Draw empty bar
- bar: Setup tray manager
* Starting module/ipc_output
- module/ipc_output: Thread id = 2
* module/ipc_output: Rebuilding cache
- bar: Force update
* Redrawing bar window
- renderer: flush(1 geom=57x24 0 0, falloff=0)
- bar: Received expose event
- background_manager: update_geometry
- background_manager: deactivating because there are no slices to observe
- background_manager: update_geometry
- background_manager: deactivating because there are no slices to observe
- command: Sending SIGTERM to running child process (26198)
- command: Waiting for pid 26198 to finish...
- command: Exited with status 0
* module/ipc_output: Rebuilding cache
* Redrawing bar window

Expected behavior

When using module/ipc with initial set to a hook, there should be no text on the bar until the hook has output something or the command finishes running

Actual behavior

The text %output% is displayed until output is received. Sometimes when there is no output and the command exits the text %output% stays there indefinitely, but I haven't been able to reproduce with a simple config. Usually it disappears when either there's output or the command finishes running.
This doesn't happen when sending an action/hook. It only happens when running the initial hook.

Window Manager and Version

i3-gaps 4.23 (2023-10-29)

Linux Distribution

NixOS 24.05

Polybar version

polybar 3.7.1

Features:  alsa -curl  i3  mpd  network(libnl)  pulseaudio  xkeyboard

X extensions:  randr ( monitors)  composite  xkb  xrm  xcursor

Build type: Release
Compiler: /nix/store/9bv7dcvmfcjnmg5mnqwqlq2wxfn8d7yi-gcc-wrapper-13.2.0/bin/g  
Compiler flags:  -O3 -DNDEBUG -Wall -Wextra -Wpedantic -Wdeprecated-copy-dtor -Wsuggest-override
Linker flags:  -Wall -Wextra -Wpedantic -Wdeprecated-copy-dtor -Wsuggest-override  -Wall -Wextra -Wpedantic -Wdeprecated-copy-dtor -Wsuggest-override

Additional Context / Screenshots

No response

@SeerLite SeerLite changed the title [Bug]: module/ipc: The literal '%output%' is displayed until output is received [Bug]: module/ipc: The literal '%output%' is displayed until output is received or the command terminates (initial hook only) Jun 19, 2024
@SeerLite
Copy link
Author

SeerLite commented Jun 20, 2024

This seems to fix it:

diff --git a/src/modules/ipc.cpp b/src/modules/ipc.cpp
index 9e337020..9bafe229 100644
--- a/src/modules/ipc.cpp
    b/src/modules/ipc.cpp
@@ -231,16  231,17 @@ namespace modules {
     assert(h >= 0 && (size_t)h < m_hooks.size());
     m_current_hook = h;
     exec_hook();
   }
 
   void ipc_module::exec_hook() {
     // Clear the output in case the command produces no output
     m_output.clear();
     update_output();
 
     try {
       command<output_policy::REDIRECTED> cmd(m_log, m_hooks[m_current_hook]->command);
       cmd.exec(false);
       cmd.tail([this](string line) { m_output = line; });
     } catch (const exception& err) {
       m_log.err("%s: Failed to execute hook command (err: %s)", name(), err.what());
       m_output.clear();

But I don't think I know what I'm doing so I'm not going to send a PR.

@patrick96
Copy link
Member

Hey, thanks for looking into this. Your solution indeed works (but there are some subtle interactions that cause it to not break anything when anything except the initial hook is executed).

I think it makes more sense to call an initial update_output in the start function. Many other modules also do that. I'll open a PR for that

@patrick96 patrick96 added this to the 3.7.2 milestone Aug 1, 2024
patrick96 added a commit to patrick96/polybar that referenced this issue Aug 1, 2024
Before, it just showed '%output%'

Fixes polybar#3131
patrick96 added a commit to patrick96/polybar that referenced this issue Aug 1, 2024
Before, it just showed '%output%'

Fixes polybar#3131
patrick96 added a commit to patrick96/polybar that referenced this issue Aug 1, 2024
Before, it just showed '%output%'

Fixes polybar#3131
patrick96 added a commit that referenced this issue Aug 1, 2024
Before, it just showed '%output%'

Fixes #3131
@patrick96
Copy link
Member

Fixed in #3140. The changes are not on master yet, they will be in the 3.7.2 release

@SeerLite
Copy link
Author

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants