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

Add dedicated dragging state for slider widget #3533

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sclu1034
Copy link
Contributor

@sclu1034 sclu1034 commented Dec 22, 2021

When trying to hook up the slider to an external value, one would usually have two data streams:

  • property::value -> set external value
  • external value changed -> .value = new_value

The problem is that without manual intervention, these two streams form a loop, as setting .value also emits property::value.

Having a dedicated "dragging" state with associated signals disconnects these data streams.

image
image

Elv13
Elv13 previously approved these changes Dec 22, 2021
@codecov
Copy link

codecov bot commented Dec 22, 2021

Codecov Report

Merging #3533 (741764a) into master (70524e7) will increase coverage by 0.00%.
The diff coverage is 98.57%.

@@           Coverage Diff            @@
##           master    #3533    +/-   ##
========================================
  Coverage   90.66%   90.67%            
========================================
  Files         852      855     +3     
  Lines       54440    54843   +403     
========================================
+ Hits        49358    49727   +369     
- Misses       5082     5116    +34     
Flag Coverage Δ
gcov 90.67% <98.57%> (+<0.01%) ⬆️
luacov 93.49% <98.57%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/wibox/widget/slider.lua 96.79% <85.71%> (+7.34%) ⬆️
tests/test-wibox-widget-slider.lua 100.00% <100.00%> (ø)
spec/wibox/test_utils.lua 51.96% <0.00%> (-27.78%) ⬇️
tests/examples/wibox/widget/defaults/slider.lua 95.65% <0.00%> (-4.35%) ⬇️
spawn.c 82.58% <0.00%> (-3.51%) ⬇️
systray.c 91.12% <0.00%> (-1.33%) ⬇️
themes/xresources/theme.lua 88.65% <0.00%> (-0.93%) ⬇️
awesome.c 80.80% <0.00%> (-0.78%) ⬇️
lib/awful/widget/taglist.lua 88.73% <0.00%> (-0.06%) ⬇️
objects/client.h 62.50% <0.00%> (ø)
... and 23 more

@Elv13
Copy link
Member

Elv13 commented Dec 22, 2021

Thanks for this. Too bad testing this would be rather non trivial. If you want to do it, you could copy/paste test-awful-widget-button.lua and replace the button with the slider.

When trying to hook up the slider to an external value, one would
usually have two data streams:

- `property::value` -> set external value
- external value changed -> `.value = new_value`

The problem is that without manual intervention, these two streams form
a loop, as setting `.value` also emits `property::value`.

The new set of signals is disconnected from the `value` property and its
signal and allows for more fine grained inspection of the dragging
state.

Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
@sclu1034 sclu1034 force-pushed the feature/slider branch 2 times, most recently from d632a67 to 6343c5f Compare December 23, 2021 18:06
@sclu1034
Copy link
Contributor Author

The test runs fine when executed solo (./tests/run.sh test-wibox-widget-slider.lua) and it uses the same fake input as test-awful-widget-button.lua, so no clue why it fails when run as part of the full set of tests.

@Elv13
Copy link
Member

Elv13 commented Dec 23, 2021

Usually, you have to check for completion in each step or return nil. This wait another event loop iteration and try again. A lot of XCB is async, so those things are not deterministic. Each step is retried 10 time when it returns nil. Adding sync should not be necessary, but is done in a few places.

I would also appreciate not adding a new hard dependency here. Even busted is optional. Many distribution package awesome and run the tests as part of the build process. Adding a new dep will potentially delay the packaging of 4.4 "because it's harder than changing the version number of the spec/control/pkgbuild file".

@sclu1034
Copy link
Contributor Author

sclu1034 commented Jan 7, 2022

Replaced the assert.spy with the got_called = true tests, as already used in test-awful-widget-button.lua.

@Elv13
Copy link
Member

Elv13 commented Jan 7, 2022

The failure is strange. I am not so sure. Maybe adding a couple empty steps after the wibox creation might help (there is a bunch of potentially async stuff going on before the widget is displayed, so the step might win or lost a race with other delayed calls?). It's 2:30 am here. I will see if I can reproduce it tomorrow.

actionless
actionless previously approved these changes Feb 2, 2022
@sclu1034
Copy link
Contributor Author

sclu1034 commented Jun 29, 2022

Spent some more time trying to investigate why the signals don't fire in the tests.

A simple function like this works perfectly fine locally, both in Xephyr and Xvfb:

-- Same wibox+slider+signals setup as in the test's first step
gears.timer.delayed_call(function()
	mouse.coords({ x = 12, y = 24 })
	root.fake_input("button_press", 1)
	mouse.coords({ x = 100, y = 24 })
	root.fake_input("button_release", 1)
end)

So clearly, async is not the issue and no waiting between those actions is necessary for the individual signals to fire.
They do only fire after the step that triggered them has finished, but that's fine, as long as triggering and checking are two separate steps.

The actual reason why no signals fired in CI is that the mouse never actually hit the widget. I don't know why, but the position at which the wibox is placed is not always consistent with what x and y are set to.

Aire-One
Aire-One previously approved these changes Jun 29, 2022
Elv13
Elv13 previously approved these changes Jun 29, 2022
tests/test-wibox-widget-slider.lua Outdated Show resolved Hide resolved
Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
@@ -303,6 +325,14 @@ function slider:set_value(value)
end
end

--- Returns `true` while the user is dragging the handle.
--
-- @method is_dragging
Copy link
Member

Choose a reason for hiding this comment

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

sorry for missing this earlier, this should be @property (there is magic to make it work)

Copy link
Contributor Author

@sclu1034 sclu1034 Jun 30, 2022

Choose a reason for hiding this comment

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

Do you mean "transform this into a property by adding get_is_dragging and set_is_dragging"?
Because there is currently no magic involved. Indexing .is_dragging returns a function, not a boolean.

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.

None yet

4 participants