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

Fixes windows size issue when using WEBVIEW_HINT_FIXED #765

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

Conversation

va1da5
Copy link

@va1da5 va1da5 commented Jun 5, 2022

There was an issue with window size when using the WEBVIEW_HINT_FIXED flag. The original function targeted widget, not the actual window and because of that, the provided size values were skewed. gtk_window_set_default_size sets default window size and gtk_window_set_resizable makes sure that the window cannot be resized. This combination follows the intended functionality.

@SteffenL
Copy link
Collaborator

SteffenL commented Jun 5, 2022

Thanks for contribution!

Would it be possible for you to provide a bit of code to reproduce the issue you mentioned?

The only difference I see is that the new code causes the width/height values to no longer be honored when passing WEBVIEW_HINT_FIXED.

#include "webview.h"

int main() {
  webview::webview w(true, nullptr);
  w.set_title("Example");
  w.set_size(480, 320, WEBVIEW_HINT_NONE);
  w.set_size(180, 120, WEBVIEW_HINT_FIXED);
  w.set_html("hello");
  w.run();
  return 0;
}

With the old code the final window size is 180x120 but with the new code it is 480x320 and I am not sure that is something one should expect.

@va1da5
Copy link
Author

va1da5 commented Jun 5, 2022

Thank you for the feedback. For my use case, I only needed to set the size once, and because of that did not try to do it multiple times. Let me know if the fix is good enough? 🙂

@SteffenL
Copy link
Collaborator

SteffenL commented Jun 5, 2022

Thanks. Not sure if this was intended but the size now looks like this on my end with 3e8b0f4 on Ubuntu 22.04.

pr_765_3e8b0f4

@va1da5
Copy link
Author

va1da5 commented Jun 5, 2022

I am not entirely sure why we get different results. However, I want to shed some light on my setup.

# OS Details:
# Fedora 36
# Gnome 42.1
# Wayland

gtk-launch --version
# 3.24.34

I have executed your proposed test case and got a bit different results. Please see the outcome below.

In my case, the size is correct only when using the flag hint WEBVIEW_HINT_NONE. The rest of the flags give incorrect sizes.

#include "webview.h"

int main() {
  webview::webview w(true, nullptr);
  w.set_title("Example");
  w.set_size(480, 320, WEBVIEW_HINT_NONE);
  w.set_size(480, 320, WEBVIEW_HINT_NONE);
  w.set_html("480x320px WEBVIEW_HINT_NONE OLD");
  w.run();
  return 0;
}

old_WEBVIEW_HINT_NONE


When using WEBVIEW_HINT_FIXED it hid the Webview window entirely.

#include "webview.h"

int main() {
  webview::webview w(true, nullptr);
  w.set_title("Example");
  w.set_size(480, 320, WEBVIEW_HINT_NONE);
  w.set_size(180, 120, WEBVIEW_HINT_FIXED);
  w.set_html("180x120px WEBVIEW_HINT_FIXED OLD");
  w.run();
  return 0;
}

Screenshot from 2022-06-05 19-35-11


With the proposed update it performed correctly (works on my machine™️).

#include "webview.h"

int main() {
  webview::webview w(true, nullptr);
  w.set_title("Example");
  w.set_size(480, 320, WEBVIEW_HINT_NONE);
  w.set_size(180, 120, WEBVIEW_HINT_FIXED);
  w.set_html("180x120px WEBVIEW_HINT_FIXED NEW");
  w.run();
  return 0;
}

Screenshot from 2022-06-05 19-38-21


I am not proficient enough to pinpoint the issue here. During the weekend I tried to build a simple emoji picker and the size of the window is crucial. That is why I got invested too much into this particular aspect of the library 🙂.

Regarding the PR, feel free to discard it. I have extracted pieces from the Webview needed for my project and updated them where it was needed. You can check and find it in the main branch.

@SteffenL
Copy link
Collaborator

SteffenL commented Jun 5, 2022

Thank you for the update!

Those are interesting results and I cannot confidently say that one or the other is more correct, but your second example certainly does not look right. I'm actually not sure the 3rd example looks right either because the window not 180x120 pixels when I measure it.

180x120_is_200x200

On my machine the content area is exactly 180x120 pixels with the old code.

@justjosias Do you know anything about this or know someone who is more familiar with GTK?

PS: Your emoji picker looks good!

@justjosias
Copy link
Member

@justjosias Do you know anything about this or know someone who is more familiar with GTK?

I don't know anything about this in particular. Maybe @eliassjogreen or @dandeto knows something about how this works in GTK.

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

Successfully merging this pull request may close these issues.

None yet

3 participants