Write code
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| /target | ||||
							
								
								
									
										208
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										208
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @ -0,0 +1,208 @@ | ||||
| # This file is automatically @generated by Cargo. | ||||
| # It is not intended for manual editing. | ||||
| version = 4 | ||||
|  | ||||
| [[package]] | ||||
| name = "bitflags" | ||||
| version = "2.9.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" | ||||
|  | ||||
| [[package]] | ||||
| name = "errno" | ||||
| version = "0.3.10" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" | ||||
| dependencies = [ | ||||
|  "libc", | ||||
|  "windows-sys", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "gethostname" | ||||
| version = "0.4.3" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "0176e0459c2e4a1fe232f984bca6890e681076abb9934f6cea7c326f3fc47818" | ||||
| dependencies = [ | ||||
|  "libc", | ||||
|  "windows-targets 0.48.5", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "libc" | ||||
| version = "0.2.171" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" | ||||
|  | ||||
| [[package]] | ||||
| name = "linux-raw-sys" | ||||
| version = "0.4.15" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" | ||||
|  | ||||
| [[package]] | ||||
| name = "rustix" | ||||
| version = "0.38.44" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" | ||||
| dependencies = [ | ||||
|  "bitflags", | ||||
|  "errno", | ||||
|  "libc", | ||||
|  "linux-raw-sys", | ||||
|  "windows-sys", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "windows-sys" | ||||
| version = "0.59.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" | ||||
| dependencies = [ | ||||
|  "windows-targets 0.52.6", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "windows-targets" | ||||
| version = "0.48.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" | ||||
| dependencies = [ | ||||
|  "windows_aarch64_gnullvm 0.48.5", | ||||
|  "windows_aarch64_msvc 0.48.5", | ||||
|  "windows_i686_gnu 0.48.5", | ||||
|  "windows_i686_msvc 0.48.5", | ||||
|  "windows_x86_64_gnu 0.48.5", | ||||
|  "windows_x86_64_gnullvm 0.48.5", | ||||
|  "windows_x86_64_msvc 0.48.5", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "windows-targets" | ||||
| version = "0.52.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" | ||||
| dependencies = [ | ||||
|  "windows_aarch64_gnullvm 0.52.6", | ||||
|  "windows_aarch64_msvc 0.52.6", | ||||
|  "windows_i686_gnu 0.52.6", | ||||
|  "windows_i686_gnullvm", | ||||
|  "windows_i686_msvc 0.52.6", | ||||
|  "windows_x86_64_gnu 0.52.6", | ||||
|  "windows_x86_64_gnullvm 0.52.6", | ||||
|  "windows_x86_64_msvc 0.52.6", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_aarch64_gnullvm" | ||||
| version = "0.48.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_aarch64_gnullvm" | ||||
| version = "0.52.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_aarch64_msvc" | ||||
| version = "0.48.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_aarch64_msvc" | ||||
| version = "0.52.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_i686_gnu" | ||||
| version = "0.48.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_i686_gnu" | ||||
| version = "0.52.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_i686_gnullvm" | ||||
| version = "0.52.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_i686_msvc" | ||||
| version = "0.48.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_i686_msvc" | ||||
| version = "0.52.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_x86_64_gnu" | ||||
| version = "0.48.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_x86_64_gnu" | ||||
| version = "0.52.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_x86_64_gnullvm" | ||||
| version = "0.48.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_x86_64_gnullvm" | ||||
| version = "0.52.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_x86_64_msvc" | ||||
| version = "0.48.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_x86_64_msvc" | ||||
| version = "0.52.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" | ||||
|  | ||||
| [[package]] | ||||
| name = "x11rb" | ||||
| version = "0.13.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "5d91ffca73ee7f68ce055750bf9f6eca0780b8c85eff9bc046a3b0da41755e12" | ||||
| dependencies = [ | ||||
|  "gethostname", | ||||
|  "rustix", | ||||
|  "x11rb-protocol", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "x11rb-protocol" | ||||
| version = "0.13.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "ec107c4503ea0b4a98ef47356329af139c0a4f7750e621cf2973cd3385ebcb3d" | ||||
|  | ||||
| [[package]] | ||||
| name = "xcrusst" | ||||
| version = "0.1.0" | ||||
| dependencies = [ | ||||
|  "x11rb", | ||||
| ] | ||||
							
								
								
									
										7
									
								
								Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								Cargo.toml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | ||||
| [package] | ||||
| name = "xcrusst" | ||||
| version = "0.1.0" | ||||
| edition = "2021" | ||||
|  | ||||
| [dependencies] | ||||
| x11rb = "0.13.1" | ||||
							
								
								
									
										112
									
								
								src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										112
									
								
								src/main.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,112 @@ | ||||
| use x11rb::connection::Connection; | ||||
| use x11rb::protocol::xproto::*; | ||||
| use x11rb::wrapper::ConnectionExt; | ||||
| use x11rb::protocol::xproto::ConnectionExt as _; | ||||
| use std::{thread, time::Duration}; | ||||
| use x11rb::protocol::Event; | ||||
|  | ||||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||||
|     // Подключиться к X-серверу | ||||
|     let (conn, screen_num) = x11rb::connect(None)?; | ||||
|     let screen = &conn.setup().roots[screen_num]; | ||||
|  | ||||
|     // Получить зелёный цвет | ||||
|     let cmap = screen.default_colormap; | ||||
| 	let white = conn.alloc_color(cmap, 65535, 65535, 65535)?.reply()?.pixel; | ||||
|     let black = conn.alloc_color(cmap, 0, 0, 0)?.reply()?.pixel; | ||||
|  | ||||
|     // Параметры окна | ||||
|     let size = 6; | ||||
|     let x = (screen.width_in_pixels / 2 - size / 2) as i16; | ||||
|     let y = (screen.height_in_pixels / 2 - size / 2) as i16; | ||||
|  | ||||
|     // Создать окно | ||||
|     let win = conn.generate_id()?; | ||||
|     conn.create_window( | ||||
|         screen.root_depth, | ||||
|         win, | ||||
|         screen.root, | ||||
|         x, | ||||
|         y, | ||||
|         size as u16, | ||||
|         size as u16, | ||||
|         0, | ||||
|         WindowClass::INPUT_OUTPUT, | ||||
|         0, | ||||
|         &CreateWindowAux::new() | ||||
|             .background_pixel(black) | ||||
|             .override_redirect(1) // Убирает управление окном менеджером окон | ||||
|             .event_mask(EventMask::EXPOSURE), | ||||
|     )?; | ||||
|  | ||||
|     // Установить окно поверх всех остальных | ||||
|     conn.configure_window( | ||||
|         win, | ||||
|         &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE), | ||||
|     )?; | ||||
|  | ||||
|     // Сделать окно невидимым для мыши | ||||
|     conn.change_window_attributes( | ||||
|         win, | ||||
|         &ChangeWindowAttributesAux::new().cursor(0), // Курсор None | ||||
|     )?; | ||||
|  | ||||
|     // Установить свойство "_NET_WM_STATE_ABOVE", чтобы окно всегда было поверх | ||||
|     let atom_net_wm_state = conn.intern_atom(false, b"_NET_WM_STATE")?.reply()?.atom; | ||||
|     let atom_net_wm_state_above = conn.intern_atom(false, b"_NET_WM_STATE_ABOVE")?.reply()?.atom; | ||||
|     conn.change_property32( | ||||
|         PropMode::REPLACE, | ||||
|         win, | ||||
|         atom_net_wm_state, | ||||
|         AtomEnum::ATOM, | ||||
|         &[atom_net_wm_state_above], | ||||
|     )?; | ||||
|  | ||||
|     // Показать окно | ||||
|     conn.map_window(win)?; | ||||
|     conn.flush()?; | ||||
|  | ||||
|     // Бесконечный цикл для поддержания работы окна | ||||
|     loop { | ||||
|         // Принудительно поднимаем окно наверх каждые 100 мс | ||||
|         conn.configure_window( | ||||
|             win, | ||||
|             &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE), | ||||
|         )?; | ||||
|         conn.flush()?; | ||||
|  | ||||
|         // Ждём 100 мс | ||||
|         thread::sleep(Duration::from_millis(100)); | ||||
|  | ||||
|         // Обрабатываем события (чтобы программа не зависала) | ||||
|         if let Some(event) = conn.poll_for_event()? { | ||||
| 			match event { | ||||
|                 Event::Expose(_) => { | ||||
|                     // Рисуем белый квадрат | ||||
|                     let gc = conn.generate_id()?; | ||||
|                     conn.create_gc( | ||||
|                         gc, | ||||
|                         win, | ||||
|                         &CreateGCAux::new() | ||||
|                             .foreground(white) | ||||
|                             .background(white), | ||||
|                     )?; | ||||
|  | ||||
|                     // Рисуем залитый квадрат | ||||
|                     conn.poly_fill_rectangle( | ||||
|                         win, | ||||
|                         gc, | ||||
|                         &[Rectangle { | ||||
|                             x: 1, | ||||
|                             y: 1, | ||||
|                             width: (size-2) as u16, | ||||
|                             height: (size-2) as u16, | ||||
|                         }], | ||||
|                     )?; | ||||
| 				} | ||||
| 				_ => {} | ||||
| 			} | ||||
|             // Обработка событий (если нужно) | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user