mirror of
https://github.com/xlmnxp/blue-recorder.git
synced 2024-11-23 17:13:11 +03:00
hide window selection in wayland
This commit is contained in:
parent
828074ace0
commit
336e8e42c5
@ -2,7 +2,7 @@ extern crate regex;
|
||||
use regex::Regex;
|
||||
use std::process::Command;
|
||||
|
||||
// this struct use "xwininfo" to get area x, y, width and height
|
||||
// This struct use "xwininfo" to get area x, y, width and height
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct AreaCapture {
|
||||
pub x: u16,
|
||||
|
@ -12,7 +12,7 @@ pub fn initialize() -> PathBuf {
|
||||
.join("blue-recorder")
|
||||
.join("config.ini");
|
||||
|
||||
// fatch and make the config file
|
||||
// Fatch and make the config file
|
||||
if !&config_path.exists() {
|
||||
let config_directories = &mut config_path.to_owned();
|
||||
config_directories.pop();
|
||||
@ -53,7 +53,7 @@ fn merge_previous_version() -> Option<PathBuf> {
|
||||
.join("blue-recorder")
|
||||
.join("config.ini");
|
||||
|
||||
// return none if config.ini not exists
|
||||
// Return none if config.ini not exists
|
||||
if !&config_path.exists() {
|
||||
return None;
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ impl Ffmpeg {
|
||||
if self.record_video.is_active() {
|
||||
let mut ffmpeg_command: Command = Command::new("ffmpeg");
|
||||
|
||||
// record video with specified width and hight
|
||||
// Record video with specified width and hight
|
||||
ffmpeg_command.arg("-video_size");
|
||||
ffmpeg_command.arg(format!("{}x{}", width, height));
|
||||
ffmpeg_command.arg("-framerate");
|
||||
@ -155,7 +155,7 @@ impl Ffmpeg {
|
||||
y
|
||||
));
|
||||
|
||||
// if show mouse switch is enabled, draw the mouse to video
|
||||
// If show mouse switch is enabled, draw the mouse to video
|
||||
ffmpeg_command.arg("-draw_mouse");
|
||||
if self.record_mouse.is_active() {
|
||||
ffmpeg_command.arg("1");
|
||||
@ -163,7 +163,7 @@ impl Ffmpeg {
|
||||
ffmpeg_command.arg("0");
|
||||
}
|
||||
|
||||
// if follow mouse switch is enabled, follow the mouse
|
||||
// If follow mouse switch is enabled, follow the mouse
|
||||
if self.follow_mouse.is_active() {
|
||||
ffmpeg_command.arg("-follow_mouse");
|
||||
ffmpeg_command.arg("centered");
|
||||
@ -172,9 +172,9 @@ impl Ffmpeg {
|
||||
ffmpeg_command.arg("1");
|
||||
ffmpeg_command.arg(self.saved_filename.as_ref().unwrap());
|
||||
ffmpeg_command.arg("-y");
|
||||
// sleep for delay
|
||||
// Sleep for delay
|
||||
sleep(Duration::from_secs(self.record_delay.value() as u64));
|
||||
// start recording and return the process id
|
||||
// Start recording and return the process id
|
||||
self.video_process_id = Some(ffmpeg_command.spawn().unwrap().id());
|
||||
return (self.video_process_id, self.audio_process_id);
|
||||
}
|
||||
@ -184,7 +184,7 @@ impl Ffmpeg {
|
||||
|
||||
pub fn stop_record(&self) {
|
||||
self.progress_widget.show();
|
||||
// kill the process to stop recording
|
||||
// Kill the process to stop recording
|
||||
self.progress_widget.set_progress("".to_string(), 1, 6);
|
||||
|
||||
if self.video_process_id.is_some() {
|
||||
@ -246,7 +246,7 @@ impl Ffmpeg {
|
||||
|
||||
self.progress_widget.set_progress("".to_string(), 4, 6);
|
||||
|
||||
// if audio record, then merge video with audio
|
||||
// If audio record, then merge video with audio
|
||||
if is_audio_record {
|
||||
self.progress_widget
|
||||
.set_progress("Save Audio Recording".to_string(), 4, 6);
|
||||
@ -283,7 +283,7 @@ impl Ffmpeg {
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
// if only audio is recording then convert it to chosen format
|
||||
// If only audio is recording then convert it to chosen format
|
||||
else if is_audio_record {
|
||||
self.progress_widget
|
||||
.set_progress("Convert Audio to choosen format".to_string(), 4, 6);
|
||||
@ -308,7 +308,7 @@ impl Ffmpeg {
|
||||
|
||||
self.progress_widget.set_progress("".to_string(), 5, 6);
|
||||
|
||||
// execute command after finish recording
|
||||
// Execute command after finish recording
|
||||
if self.command.text().trim() != "" {
|
||||
self.progress_widget.set_progress(
|
||||
"execute custom command after finish".to_string(),
|
||||
@ -326,7 +326,7 @@ impl Ffmpeg {
|
||||
pub fn play_record(self) {
|
||||
if self.saved_filename.is_some() {
|
||||
if is_snap() {
|
||||
// open the video using snapctrl for snap package
|
||||
// Open the video using snapctrl for snap package
|
||||
Command::new("snapctl")
|
||||
.arg("user-open")
|
||||
.arg(self.saved_filename.unwrap())
|
||||
|
46
src/main.rs
46
src/main.rs
@ -17,14 +17,14 @@ use std::process::{Command, Stdio};
|
||||
use std::rc::Rc;
|
||||
|
||||
fn main() {
|
||||
//create new application
|
||||
//Create new application
|
||||
let application = Application::new(Some("sa.sy.blue-recorder"), Default::default(),);
|
||||
application.connect_activate(build_ui);
|
||||
application.run();
|
||||
}
|
||||
|
||||
pub fn build_ui(application: &Application) {
|
||||
// use "GDK_BACKEND=x11" to make xwininfo work in Wayland by using XWayland
|
||||
// Use "GDK_BACKEND=x11" to make xwininfo work in Wayland by using XWayland
|
||||
std::env::set_var("GDK_BACKEND", "x11");
|
||||
if gtk::init().is_err() {
|
||||
println!("Failed to initialize GTK.");
|
||||
@ -34,7 +34,7 @@ pub fn build_ui(application: &Application) {
|
||||
let ui_src = include_str!("../interfaces/main.ui").to_string();
|
||||
let builder: Builder = Builder::from_string(ui_src.as_str());
|
||||
|
||||
// translate
|
||||
// Translate
|
||||
let mut po_path_abs = {
|
||||
let mut current_exec_dir = std::env::current_exe().unwrap();
|
||||
current_exec_dir.pop();
|
||||
@ -53,10 +53,10 @@ pub fn build_ui(application: &Application) {
|
||||
bindtextdomain("blue-recorder", po_path_abs.to_str().unwrap()).unwrap();
|
||||
textdomain("blue-recorder").unwrap();
|
||||
|
||||
// config initialize
|
||||
// Config initialize
|
||||
config_management::initialize();
|
||||
|
||||
// get Objects from UI
|
||||
// Get Objects from UI
|
||||
let area_chooser_window: Window = builder.object("area_chooser_window").unwrap();
|
||||
let area_grab_button: ToggleButton = builder.object("area_grab_button").unwrap();
|
||||
let area_grab_icon: Image = builder.object("area_grab_icon").unwrap();
|
||||
@ -99,10 +99,15 @@ pub fn build_ui(application: &Application) {
|
||||
main_window.set_application(Some(application));
|
||||
area_chooser_window.set_title(Some(&gettext("Area Chooser"))); //title is hidden
|
||||
|
||||
//hide stop & play buttons
|
||||
//Hide stop & play buttons
|
||||
stop_button.hide();
|
||||
play_button.hide();
|
||||
|
||||
//Hide window grab button in Wayland
|
||||
if is_wayland() {
|
||||
window_grab_button.hide();
|
||||
}
|
||||
|
||||
// Entries
|
||||
filename_entry.set_placeholder_text(Some(&gettext("Default filename:")));
|
||||
command_entry.set_placeholder_text(Some(&gettext("Default command:")));
|
||||
@ -122,7 +127,7 @@ pub fn build_ui(application: &Application) {
|
||||
//format_chooser_combobox.append(Some("nut"), &gettext("NUT (NUT Recording Format)"));
|
||||
format_chooser_combobox.set_active(Some(0));
|
||||
|
||||
// get audio sources
|
||||
// Get audio sources
|
||||
let sources_descriptions: Vec<String> = {
|
||||
let list_sources_child = Command::new("pactl")
|
||||
.args(&["list", "sources"])
|
||||
@ -303,13 +308,18 @@ pub fn build_ui(application: &Application) {
|
||||
folder_chooser_label.set_label(&folder_chooser_name.to_string_lossy());
|
||||
let folder_chooser_icon = config_management::folder_icon(folder_chooser_name.to_str());
|
||||
folder_chooser_image.set_icon_name(Some(folder_chooser_icon));
|
||||
// show file chooser dialog
|
||||
// Show file chooser dialog
|
||||
folder_chooser_button.connect_clicked(glib::clone!(@strong folder_chooser_native => move |_| {
|
||||
folder_chooser_native.connect_response(glib::clone!(@strong folder_chooser_native, @strong folder_chooser_label, @strong folder_chooser_image => move |_, response| {
|
||||
if response == gtk::ResponseType::Accept {
|
||||
let folder_chooser = folder_chooser_native.file().unwrap();
|
||||
let folder_chooser_name = folder_chooser.basename().unwrap();
|
||||
folder_chooser_label.set_label(&folder_chooser_name.to_string_lossy());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let folder_chooser_icon = config_management::folder_icon(folder_chooser_name.to_str());
|
||||
folder_chooser_image.set_icon_name(Some(folder_chooser_icon));
|
||||
};
|
||||
@ -319,7 +329,7 @@ pub fn build_ui(application: &Application) {
|
||||
}));
|
||||
|
||||
// --- connections
|
||||
// show dialog window when about button clicked then hide it after close
|
||||
// Show dialog window when about button clicked then hide it after close
|
||||
let _about_dialog: AboutDialog = about_dialog.to_owned();
|
||||
about_button.connect_clicked(move |_| {
|
||||
_about_dialog.show();
|
||||
@ -365,7 +375,7 @@ pub fn build_ui(application: &Application) {
|
||||
_progress_dialog.hide();
|
||||
});
|
||||
|
||||
// init record struct
|
||||
// Init record struct
|
||||
let ffmpeg_record_interface: Rc<RefCell<Ffmpeg>> = Rc::new(RefCell::new(Ffmpeg {
|
||||
filename: (folder_chooser, filename_entry, format_chooser_combobox),
|
||||
record_video: video_switch,
|
||||
@ -397,7 +407,7 @@ pub fn build_ui(application: &Application) {
|
||||
_area_capture.height,
|
||||
) {
|
||||
(None, None) => {
|
||||
// do nothing if the start_record function return nothing
|
||||
// Do nothing if the start_record function return nothing
|
||||
}
|
||||
_ => {
|
||||
_record_button.hide();
|
||||
@ -463,22 +473,22 @@ pub fn build_ui(application: &Application) {
|
||||
about_dialog.set_modal(true);
|
||||
|
||||
// Windows
|
||||
// hide area chooser after it deleted.
|
||||
// Hide area chooser after it deleted.
|
||||
let _area_chooser_window = area_chooser_window.clone();
|
||||
area_chooser_window.connect_close_request (move |_| {
|
||||
_area_chooser_window.hide();
|
||||
gtk::Inhibit(true)
|
||||
});
|
||||
|
||||
// close the application when main window destroy
|
||||
// Close the application when main window destroy
|
||||
main_window.connect_destroy(move |main_window| {
|
||||
let mut _ffmpeg_record_interface = ffmpeg_record_interface.clone();
|
||||
// stop recording before close the application
|
||||
// Stop recording before close the application
|
||||
_ffmpeg_record_interface.borrow_mut().clone().stop_record();
|
||||
main_window.close();
|
||||
});
|
||||
|
||||
// apply css
|
||||
// Apply css
|
||||
let provider = CssProvider::new();
|
||||
provider
|
||||
.load_from_data(include_str!("styles/global.css").as_bytes());
|
||||
@ -488,5 +498,11 @@ pub fn build_ui(application: &Application) {
|
||||
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
);
|
||||
|
||||
fn is_wayland() -> bool {
|
||||
std::env::var("XDG_SESSION_TYPE")
|
||||
.unwrap_or_default()
|
||||
.eq_ignore_ascii_case("wayland")
|
||||
}
|
||||
|
||||
main_window.show();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user