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

[GUI] [linux] Support creating fullscreen window by "ti.GUI(fullscreen=True)" #1921

Merged
merged 8 commits into from
Oct 8, 2020

Conversation

archibate
Copy link
Collaborator

Related issue = taichi-dev/taichi_three#20 (comment)

[Click here for the format server]


This PR use the method in https://stackoverflow.com/questions/9083273/x11-fullscreen-window-opengl to support fullscreen on X11. We'd add this to Win32 and Cocoa too iapr.

@archibate archibate changed the title [GUI] Support creating fullscreen window by "ti.GUI(fullscreen=True)" [GUI] [linux] Support creating fullscreen window by "ti.GUI(fullscreen=True)" on X11 Oct 4, 2020
@codecov
Copy link

codecov bot commented Oct 4, 2020

Codecov Report

Merging #1921 into master will increase coverage by 0.92%.
The diff coverage is 16.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1921      +/-   ##
==========================================
+ Coverage   42.80%   43.72%   +0.92%     
==========================================
  Files          45       45              
  Lines        6413     6207     -206     
  Branches     1101     1103       +2     
==========================================
- Hits         2745     2714      -31     
+ Misses       3498     3322     -176     
- Partials      170      171       +1     
Impacted Files Coverage Δ
python/taichi/misc/gui.py 8.68% <16.66%> (ø)
.../build/taichi-dev/taichi/python/taichi/__init__.py
.../build/taichi-dev/taichi/python/taichi/lang/ops.py
...d/taichi-dev/taichi/python/taichi/core/settings.py
...build/taichi-dev/taichi/python/taichi/lang/tape.py
...build/taichi-dev/taichi/python/taichi/lang/util.py
...uild/taichi-dev/taichi/python/taichi/lang/shell.py
...taichi-dev/taichi/python/taichi/lang/common_ops.py
...uild/taichi-dev/taichi/python/taichi/misc/image.py
...ild/taichi-dev/taichi/python/taichi/tools/video.py
... and 81 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 12e02be...ebc7e0a. Read the comment docs.

style &= ~WS_CAPTION & ~WS_SIZEBOX;
SetWindowLong(hwnd, GWL_STYLE, style);
SetWindowPos(hwnd, NULL, 0, 0, GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN), SWP_NOZORDER);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JYLeeLYJ Would you confirm if this part works? many thanks!

@archibate archibate changed the title [GUI] [linux] Support creating fullscreen window by "ti.GUI(fullscreen=True)" on X11 [GUI] [linux] Support creating fullscreen window by "ti.GUI(fullscreen=True)" Oct 5, 2020
@thinking-tower
Copy link
Contributor

LGTM! I ran it on Ubuntu 18.04 and tried it on fractals, nbody_oscillator and taichi_logo and it works. Not all of the examples listen for an escape key, so it was a bit of an issue for me to minimize the window until I found the keyboard shortcut.

For MacOS:

Add

  if (fullscreen) {
    call(window, "toggleFullScreen:");
  }

to the end of GUI::create_window() in taichi/gui/cocoa.cpp and it should start in full screen.

taichi/taichi/gui/cocoa.cpp

Lines 268 to 311 in 094baad

void GUI::create_window() {
clscall("NSApplication", "sharedApplication");
if (NSApp == nullptr) {
fprintf(stderr, "Failed to initialized NSApplication.\nterminating.\n");
return;
}
// I finally found how to bring the NSWindow to the front and to handle
// keyboard events in these posts:
// https://stackoverflow.com/a/11010614/12003165
// http://www.cocoawithlove.com/2010/09/minimalist-cocoa-programming.html
//
// The problem was that, a Cocoa app without NIB files (app bundle,
// info.plist, whatever the meta files are) by default has a policy of
// NSApplicationActivationPolicyProhibited.
// (https://developer.apple.com/documentation/appkit/nsapplicationactivationpolicy/nsapplicationactivationpolicyprohibited?language=objc)
call(NSApp, "setActivationPolicy:", NSApplicationActivationPolicyRegular);
// This doesn't seem necessary, but in case there's some weird bug causing the
// Window not to be brought to the front, try enable this.
// https://stackoverflow.com/a/7460187/12003165
// call(NSApp, "activateIgnoringOtherApps:", YES);
img_data_length = width * height * 4;
img_data.resize(img_data_length);
auto appDelObj = clscall("AppDelegate", "alloc");
appDelObj = call(appDelObj, "init");
call(NSApp, "setDelegate:", appDelObj);
window = clscall("NSWindow", "alloc");
auto rect = (CGRect){{0, 0}, {CGFloat(width), CGFloat(height)}};
call(window, "initWithContentRect:styleMask:backing:defer:", rect,
(NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask |
NSMiniaturizableWindowMask),
0, false);
view = call(clscall(kTaichiViewClassName, "alloc"), "initWithFrame:", rect);
gui_from_id[view] = this;
// Needed by NSWindowDelegate
gui_from_id[window] = this;
// Use layer to speed up the draw
// https://developer.apple.com/documentation/appkit/nsview/1483695-wantslayer?language=objc
call(view, "setWantsLayer:", YES);
call(window, "setDelegate:", appDelObj);
call(window, "setContentView:", view);
call(window, "becomeFirstResponder");
call(window, "setAcceptsMouseMovedEvents:", YES);
call(window, "makeKeyAndOrderFront:", window);
}

Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

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

LGTM!

@archibate archibate added the LGTM label Oct 6, 2020
@archibate archibate merged commit ddf7513 into taichi-dev:master Oct 8, 2020
@yuanming-hu yuanming-hu mentioned this pull request Oct 10, 2020
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