-
Notifications
You must be signed in to change notification settings - Fork 567
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
Wayland #1498
Closed
Closed
Wayland #1498
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Copyright 2018 The Druid Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/// An example that is as simple as possible (just throw up an empty window). | ||
use std::any::Any; | ||
|
||
use druid_shell::kurbo::{Point, Rect, Size}; | ||
use druid_shell::piet::{Color, FixedLinearGradient, GradientStop, RenderContext}; | ||
|
||
use druid_shell::{ | ||
Application, Cursor, FileDialogToken, FileInfo, KeyEvent, MouseEvent, Region, TimerToken, | ||
WinHandler, WindowBuilder, WindowHandle, | ||
}; | ||
|
||
#[derive(Default)] | ||
struct HelloState { | ||
size: Size, | ||
handle: Option<WindowHandle>, | ||
} | ||
|
||
impl WinHandler for HelloState { | ||
fn connect(&mut self, handle: &WindowHandle) { | ||
self.handle = Some(handle.clone()); | ||
} | ||
|
||
fn prepare_paint(&mut self) { | ||
self.handle.as_mut().unwrap().invalidate(); | ||
} | ||
|
||
fn paint(&mut self, piet: &mut piet_common::Piet, _: &Region) { | ||
// draw a gradient so we can see what's going on. | ||
let brush = piet | ||
.gradient(FixedLinearGradient { | ||
start: Point::ZERO, | ||
end: self.size.to_vec2().to_point(), | ||
stops: vec![ | ||
GradientStop { | ||
pos: 0.0, | ||
color: Color::RED, | ||
}, | ||
GradientStop { | ||
pos: 1.0, | ||
color: Color::BLUE, | ||
}, | ||
], | ||
}) | ||
.unwrap(); | ||
piet.fill(Rect::ZERO.with_size(self.size), &brush); | ||
} | ||
|
||
fn command(&mut self, id: u32) { | ||
println!("command id {}", id); | ||
} | ||
|
||
fn open_file(&mut self, _token: FileDialogToken, file_info: Option<FileInfo>) { | ||
println!("open file result: {:?}", file_info); | ||
} | ||
|
||
fn key_down(&mut self, event: KeyEvent) -> bool { | ||
println!("keydown: {:?}", event); | ||
false | ||
} | ||
|
||
fn key_up(&mut self, event: KeyEvent) { | ||
println!("keyup: {:?}", event); | ||
} | ||
|
||
fn wheel(&mut self, event: &MouseEvent) { | ||
println!("mouse_wheel {:?}", event); | ||
} | ||
|
||
fn mouse_move(&mut self, event: &MouseEvent) { | ||
self.handle.as_mut().unwrap().set_cursor(&Cursor::Arrow); | ||
println!("mouse_move {:?}", event); | ||
} | ||
|
||
fn mouse_down(&mut self, event: &MouseEvent) { | ||
println!("mouse_down {:?}", event); | ||
} | ||
|
||
fn mouse_up(&mut self, event: &MouseEvent) { | ||
println!("mouse_up {:?}", event); | ||
} | ||
|
||
fn timer(&mut self, id: TimerToken) { | ||
println!("timer fired: {:?}", id); | ||
} | ||
|
||
fn size(&mut self, size: Size) { | ||
self.size = size; | ||
} | ||
|
||
fn got_focus(&mut self) { | ||
println!("Got focus"); | ||
} | ||
|
||
fn lost_focus(&mut self) { | ||
println!("Lost focus"); | ||
} | ||
|
||
fn request_close(&mut self) { | ||
self.handle.as_ref().unwrap().close(); | ||
} | ||
|
||
fn destroy(&mut self) { | ||
Application::global().quit() | ||
} | ||
|
||
fn as_any(&mut self) -> &mut dyn Any { | ||
self | ||
} | ||
} | ||
|
||
fn main() { | ||
simple_logger::SimpleLogger::new().init().unwrap(); | ||
let app = Application::new().unwrap(); | ||
let mut builder = WindowBuilder::new(app.clone()); | ||
builder.set_handler(Box::new(HelloState::default())); | ||
builder.set_title("Hello example"); | ||
|
||
let window = builder.build().unwrap(); | ||
window.show(); | ||
|
||
app.run(None); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate::TimerToken; | ||
use std::{cmp::Ordering, time::Instant}; | ||
|
||
/// A timer is a deadline (`std::Time::Instant`) and a `TimerToken`. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub(crate) struct Timer<T> { | ||
deadline: Instant, | ||
token: TimerToken, | ||
pub data: T, | ||
} | ||
|
||
impl<T> Timer<T> { | ||
pub(crate) fn new(deadline: Instant, data: T) -> Self { | ||
let token = TimerToken::next(); | ||
Self { | ||
deadline, | ||
token, | ||
data, | ||
} | ||
} | ||
|
||
pub(crate) fn deadline(&self) -> Instant { | ||
self.deadline | ||
} | ||
|
||
pub(crate) fn token(&self) -> TimerToken { | ||
self.token | ||
} | ||
} | ||
|
||
impl<T: Eq + PartialEq> Ord for Timer<T> { | ||
/// Ordering is so that earliest deadline sorts first | ||
// "Earliest deadline first" that a std::collections::BinaryHeap will have the earliest timer | ||
// at its head, which is just what is needed for timer management. | ||
fn cmp(&self, other: &Self) -> Ordering { | ||
self.deadline.cmp(&other.deadline).reverse() | ||
} | ||
} | ||
|
||
impl<T: Eq + PartialEq> PartialOrd for Timer<T> { | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
Some(self.cmp(other)) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior ok the wayland backend is to only hold weak handles to the application in the windows, so that the application might be dropped and then the window used. Not sure if this is correct.