Skip to content

Commit db913c9

Browse files
committed
Add other dependencies
1 parent 4a3aadb commit db913c9

File tree

10 files changed

+12329
-0
lines changed

10 files changed

+12329
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

libDynamicWallpapaper/Cargo.lock

Lines changed: 4191 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libDynamicWallpapaper/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "libDynamicWallpapaper"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
icrate = {version = "0.0.4", features = ["AppKit", "AppKit_NSWindow", "AppKit_NSScreen", "AppKit_NSView", "Foundation", "Foundation_NSString", "Foundation_NSURL"]}
10+
libResourceManager = { path = "../libResourceManager" }

libDynamicWallpapaper/src/lib.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#![allow(non_snake_case)]
2+
3+
use icrate::AppKit::{NSBackingStoreBuffered, NSScreen, NSView, NSWindow, NSWindowStyleMaskUnifiedTitleAndToolbar};
4+
use icrate::objc2::{class, ClassType, msg_send};
5+
use icrate::objc2::rc::Id;
6+
use std::borrow::Borrow;
7+
use icrate::Foundation::{NSString, NSURL};
8+
use icrate::objc2::runtime::AnyObject;
9+
10+
unsafe fn get_current_screen() -> Id<NSScreen> {
11+
return NSScreen::mainScreen().unwrap();
12+
}
13+
14+
pub fn close_window(window: Id<NSWindow>) {
15+
unsafe { window.close(); };
16+
}
17+
18+
/* Currently producing a segfault.
19+
pub fn close_window_on_screen(window: Id<NSWindow>) -> bool {
20+
let mut remove = false;
21+
unsafe {
22+
if window.isOnActiveSpace() {
23+
remove = true;
24+
window.close();
25+
}
26+
}
27+
return remove;
28+
}
29+
*/
30+
31+
pub fn apply_to_screen(identifier: String) -> Id<NSWindow> {
32+
33+
let file_path = libResourceManager::get_file_path(identifier);
34+
35+
unsafe {
36+
let screen = get_current_screen();
37+
let frame = screen.frame();
38+
let background_window_alloc = NSWindow::alloc().unwrap();
39+
let background_window = NSWindow::initWithContentRect_styleMask_backing_defer(
40+
Some(background_window_alloc),
41+
frame,
42+
NSWindowStyleMaskUnifiedTitleAndToolbar,
43+
NSBackingStoreBuffered,
44+
false
45+
);
46+
background_window.makeKeyAndOrderFront(None);
47+
background_window.setLevel(-2147483628 + 15);
48+
let view_alloc = NSView::alloc().unwrap();
49+
let view = NSView::initWithFrame(Some(view_alloc), frame);
50+
background_window.setContentView(Some(view.borrow()));
51+
52+
let video_url_alloc = NSURL::alloc().unwrap();
53+
let file_ns_string = NSString::from_str(file_path.as_str());
54+
let video_url = NSURL::initFileURLWithPath(Some(video_url_alloc), &*file_ns_string);
55+
56+
let video_gravity_string = NSString::from_str("AVLayerVideoGravityResizeAspectFill");
57+
58+
let av_player_class = class!(AVPlayer);
59+
let av_player: &AnyObject = msg_send![av_player_class, playerWithURL: &*video_url];
60+
let av_playerlayer_class = class!(AVPlayerLayer);
61+
let av_playerlayer: &AnyObject = msg_send![av_playerlayer_class, playerLayerWithPlayer: av_player];
62+
let _: () = msg_send![av_playerlayer, setVideoGravity: &*video_gravity_string];
63+
let _: () = msg_send![&view, setLayer: av_playerlayer];
64+
let _: () = msg_send![&view, setWantsLayer: true];
65+
let _: () = msg_send![&*av_player, play];
66+
background_window.setCollectionBehavior(16);
67+
68+
return background_window;
69+
};
70+
}

0 commit comments

Comments
 (0)