implement open_file_dialog, save_file_dialog and set_window_title for linux #15
@ -56,6 +56,8 @@ static ImGui_ImplVulkanH_Window g_MainWindowData;
|
||||
static uint32_t g_MinImageCount = 2;
|
||||
static bool g_SwapChainRebuild = false;
|
||||
|
||||
static GLFWwindow *window;
|
||||
|
||||
static void glfw_error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
|
||||
@ -361,7 +363,7 @@ int main(int, char**)
|
||||
|
||||
// Create window with Vulkan context
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
GLFWwindow* window = glfwCreateWindow(1280, 720, "Work Calendar", nullptr, nullptr);
|
||||
window = glfwCreateWindow(1600, 900, "Work Calendar", nullptr, nullptr);
|
||||
if (!glfwVulkanSupported())
|
||||
{
|
||||
printf("GLFW: Vulkan Not Supported\n");
|
||||
@ -527,3 +529,73 @@ int main(int, char**)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int run_command_and_return_exit_code(const char *command) {
|
||||
FILE *process = popen(command, "re");
|
||||
if (!process) return -1;
|
||||
|
||||
return pclose(process);
|
||||
}
|
||||
|
||||
static char *run_command_and_return_stdout(const char *command, size_t buffer_size) {
|
||||
FILE *process = popen(command, "re");
|
||||
if (!process) return NULL;
|
||||
|
||||
char *result = (char *)calloc(1, buffer_size);
|
||||
if (!result) return NULL;
|
||||
|
||||
for (char *ptr = result; (result + buffer_size - ptr) > 1 && fgets(ptr, result + buffer_size - ptr, process); ptr = ptr + strlen(ptr));
|
||||
|
||||
if (!feof(process)) {
|
||||
free(result);
|
||||
pclose(process);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pclose(process)) {
|
||||
free(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
char *open_file_dialog() {
|
||||
char *path = NULL;
|
||||
|
||||
if (run_command_and_return_exit_code("zenity --version") == 0) {
|
||||
path = run_command_and_return_stdout("zenity --title=\"Open Calendar\" --modal --file-selection --file-filter=\"Workcalendar (*.wcl) | *.wcl\"", PATH_MAX);
|
||||
} else if (run_command_and_return_exit_code("kdialog --version") == 0) {
|
||||
path = run_command_and_return_stdout("kdialog --title \"Open Calendar\" --getopenfilename . \"Workcalendar(*.wcl)\"", PATH_MAX);
|
||||
}
|
||||
|
||||
if (!path) return NULL;
|
||||
|
||||
size_t len = strlen(path);
|
||||
if (len && path[len-1] == '\n')
|
||||
path[len-1] = '\0';
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
char *save_file_dialog() {
|
||||
char *path = NULL;
|
||||
|
||||
if (run_command_and_return_exit_code("zenity --version") == 0) {
|
||||
path = run_command_and_return_stdout("zenity --title=\"Save Calendar\" --modal --file-selection --save --file-filter=\"Workcalendar (*.wcl) | *.wcl\"", PATH_MAX);
|
||||
} else if (run_command_and_return_exit_code("kdialog --version") == 0) {
|
||||
path = run_command_and_return_stdout("kdialog --title \"Save Calendar\" --getsavefilename . \"Workcalendar(*.wcl)\"", PATH_MAX);
|
||||
}
|
||||
|
||||
if (!path) return NULL;
|
||||
|
||||
size_t len = strlen(path);
|
||||
if (len && path[len-1] == '\n')
|
||||
path[len-1] = '\0';
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void set_window_title(const char *title) {
|
||||
glfwSetWindowTitle(window, title);
|
||||
}
|
||||
|
||||
@ -215,6 +215,13 @@ void per_frame(){
|
||||
if(save_file_path) free(save_file_path);
|
||||
save_file_path = new_save_file_path;
|
||||
save();
|
||||
|
||||
char *title = (char *)calloc(1, strlen("Work Calendar - ") + strlen(save_file_path) + 1);
|
||||
memcpy(title, "Work Calendar - ", strlen("Work Calendar - "));
|
||||
memcpy(title + strlen("Work Calendar - "), save_file_path, strlen(save_file_path));
|
||||
|
||||
set_window_title(title);
|
||||
free(title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user