Skip to content

Commit ae6b6b0

Browse files
author
Cecil
committed
for #430 - fix some compiler warnings.
finish moving the monitors and windows console code to separate files.
1 parent 3d84e27 commit ae6b6b0

File tree

4 files changed

+12
-187
lines changed

4 files changed

+12
-187
lines changed

shoes/app.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "shoes/types/native.h"
1717
#include "shoes/types/event.h"
1818

19+
RUBY_EXTERN ID s_shift_key, s_control_key;
20+
1921
// Global var:
2022
int shoes_app_serial_num = 0;
2123

@@ -637,7 +639,6 @@ shoes_code shoes_app_motion(shoes_app *app, int x, int y, int mods) {
637639
shoes_canvas_send_motion(app->canvas, x, y, Qnil, modifiers);
638640
return SHOES_OK;
639641
}
640-
EXTERN ID s_shift_key, s_control_key;
641642

642643
shoes_code shoes_app_click(shoes_app *app, int button, int x, int y, int mods) {
643644
app->mouseb = button;

shoes/console/gtk-terminal.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
#include <sys/types.h>
55
#include <signal.h>
66

7-
#include "tesi.h"
87
#include <gdk/gdkkeysyms.h>
98
#include "shoes/app.h"
109
#include "shoes/ruby.h"
1110
#include "shoes/config.h"
1211
#include "shoes/world.h"
12+
#include "tesi.h"
1313

1414
#include "shoes/native/gtk/gtkcss.h"
1515
extern char *colorstrings[];

shoes/console/tesi.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
#ifndef TESI_H
22
#define TESI_H
33

4-
// _XOPEN_SOURCE for posix_openpt() from stdlin and fcntl
4+
// _XOPEN_SOURCE for posix_openpt() for stdlin and fcntl
5+
#if defined(__linux__) || defined(__GLIBC__) || defined(__GNU__)
6+
#ifndef _GNU_SOURCE
7+
#define _GNU_SOURCE /* GNU glibc grantpt() prototypes */
8+
#endif
9+
#endif
510
#define _XOPEN_SOURCE
11+
#define __USE_XOPEN_EXTENDED
612
#include <stdio.h>
713
#include <stdlib.h>
814
#include <fcntl.h>

shoes/native/gtk.c

+2-184
Original file line numberDiff line numberDiff line change
@@ -1836,188 +1836,6 @@ VALUE shoes_native_to_s(VALUE text) {
18361836
return text;
18371837
}
18381838

1839-
1840-
1841-
#ifdef SHOES_GTK_WIN32
1842-
// hat tip: https://justcheckingonall.wordpress.com/2008/08/29/console-window-win32-app/
1843-
#include <stdio.h>
1844-
#include <io.h>
1845-
#include <fcntl.h>
1846-
1847-
1848-
// called from main.c(skel) on Windows - works fine
1849-
static FILE* shoes_console_out = NULL;
1850-
static FILE* shoes_console_in = NULL;
1851-
1852-
int shoes_win32_console() {
1853-
1854-
if (AllocConsole() == 0) {
1855-
// cshoes.exe can get here
1856-
printf("Already have console\n");
1857-
return 0;
1858-
}
1859-
1860-
HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
1861-
int hCrt = _open_osfhandle((long) handle_out, _O_TEXT);
1862-
FILE* hf_out = _fdopen(hCrt, "w");
1863-
setvbuf(hf_out, NULL, _IONBF, 1);
1864-
*stdout = *hf_out;
1865-
HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
1866-
hCrt = _open_osfhandle((long) handle_in, _O_TEXT);
1867-
FILE* hf_in = _fdopen(hCrt, "r");
1868-
setvbuf(hf_in, NULL, _IONBF, 128);
1869-
*stdin = *hf_in;
1870-
1871-
//* stash handles
1872-
shoes_console_out = hf_out;
1873-
shoes_console_in = hf_in;
1874-
return 1;
1875-
}
1876-
1877-
// Called by Shoes after ruby/gtk/shoes is initialized and running
1878-
int shoes_native_terminal() {
1879-
// has a console been setup by --console flag?
1880-
if (shoes_console_out == NULL) {
1881-
if (shoes_win32_console() == 0) { // cshoes.exe can do this
1882-
return 1;
1883-
}
1884-
}
1885-
// convert the (cached) FILE * for what ruby wants for fd[0], [1]...
1886-
if (dup2(_fileno(shoes_console_out), 1) == -1) {
1887-
printf("failed dup2 of stdout\n");
1888-
}
1889-
if (dup2(_fileno(shoes_console_out), 2) == -1) {
1890-
printf("failed dup2 of stderr\n");
1891-
}
1892-
if (dup2(_fileno(shoes_console_in), 0) == -1) {
1893-
printf("failed dup2 of stdin\n");
1894-
}
1895-
printf("created win32 console\n");
1896-
return 1;
1897-
}
1898-
1899-
// For bug #428
1900-
int shoes_win10_gtk3_22_check() {
1901-
if (gtk_get_minor_version() < 22)
1902-
return 0;
1903-
// borrowed from
1904-
// https://stackoverflow.com/questions/32115255/c-how-to-detect-windows-10
1905-
int ret = 0;
1906-
NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEXW);
1907-
OSVERSIONINFOEXW osInfo;
1908-
1909-
*(FARPROC*)&RtlGetVersion = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
1910-
1911-
if (NULL != RtlGetVersion)
1912-
{
1913-
osInfo.dwOSVersionInfoSize = sizeof(osInfo);
1914-
RtlGetVersion(&osInfo);
1915-
ret = osInfo.dwMajorVersion;
1916-
}
1917-
//printf("windows version %i\n", ret); // win 7 returns '6' go figure
1918-
return ret == 10;
1919-
}
1920-
#else
1921-
/*
1922-
int shoes_native_console(char *app_path)
1923-
{
1924-
//printf("init gtk console\n");
1925-
shoes_native_app_console(app_path);
1926-
printf("gtk\010k\t console \t\tcreated\n"); //test \b \t in string
1927-
return 1;
1928-
}
1929-
*/
1930-
#endif
1931-
1932-
/*
1933-
* ------- monitor handling --------
1934-
* As usual, gtk 3.22 'fixes' things with deprecations.
1935-
*
1936-
* Currrently using pre 3.22 API.
1937-
* Screen width is the sum of all monitors. Height is the max of all
1938-
* monitors. Do not address monitors just set x.
1939-
*/
1940-
int shoes_native_monitor_default() {
1941-
GdkScreen *screen;
1942-
GdkDisplay *display;
1943-
display = gdk_display_get_default();
1944-
screen = gdk_display_get_default_screen(display);
1945-
int mon;
1946-
mon = gdk_screen_get_primary_monitor(screen);
1947-
return mon;
1948-
}
1949-
1950-
void shoes_native_monitor_geometry(int idx, shoes_monitor_t *geo) {
1951-
1952-
GdkScreen *screen;
1953-
screen = gdk_screen_get_default();
1954-
GdkRectangle r;
1955-
// workarea approximates visibleFrame on OSX
1956-
//gdk_screen_get_monitor_geometry(screen, idx, &r);
1957-
gdk_screen_get_monitor_workarea(screen, idx, &r);
1958-
geo->x = r.x;
1959-
geo->y = r.y;
1960-
geo->width = r.width;
1961-
geo->height = r.height;
1962-
}
1963-
1964-
int shoes_native_monitor_count() {
1965-
GdkScreen *screen;
1966-
screen = gdk_screen_get_default();
1967-
int cnt = 0;
1968-
cnt = gdk_screen_get_n_monitors(screen);
1969-
return cnt;
1970-
}
1971-
1972-
// Sets/moves the window onto monitor
1973-
void shoes_native_monitor_set(shoes_app *app) {
1974-
GtkWindow *window = (GtkWindow *)app->os.window;
1975-
GdkDisplay *display;
1976-
GdkScreen *screen;
1977-
screen = gdk_screen_get_default();
1978-
display = gdk_screen_get_display(screen);
1979-
// sanity checks
1980-
int cnt = 0;
1981-
cnt = gdk_screen_get_n_monitors(screen);
1982-
int realmon;
1983-
if (app->monitor < cnt && app->monitor >= 0)
1984-
realmon = app->monitor;
1985-
else {
1986-
realmon = 0;
1987-
}
1988-
/*
1989-
fprintf(stderr, "Screen w: %d x h: %d\n", gdk_screen_get_width(screen),
1990-
gdk_screen_get_height(screen));
1991-
fprintf(stderr, "Switch to monitor %d of %d\n", realmon, cnt);
1992-
*/
1993-
GdkRectangle r;
1994-
gdk_screen_get_monitor_geometry(screen, realmon, &r);
1995-
gtk_window_move(window, app->x + r.x, app->y);
1996-
// TODO: do a better job of positioning. Worth the effort?
1997-
}
1998-
1999-
// returns the Shoes monitor number that the window is on
2000-
int shoes_native_monitor_get(shoes_app *app) {
2001-
GtkWindow *window = (GtkWindow *)app->os.window;
2002-
GdkDisplay *display;
2003-
GdkScreen *screen;
2004-
screen = gtk_window_get_screen(window);
2005-
// determine which monitor that is. Remember: Gtk screen holds Gtk monitors
2006-
int x, y, cnt, i;
2007-
gtk_window_get_position (window, &x, &y);
2008-
cnt = gdk_screen_get_n_monitors(screen);
2009-
for (i = 0; i < cnt; i++) {
2010-
GdkRectangle r;
2011-
gdk_screen_get_monitor_geometry(screen, i, &r);
2012-
if ((x >= r.x) && (x <= (r.x +r.width)) && (y >= r.y) && (y <= (r.y +r.height))) {
2013-
return i;
2014-
}
2015-
}
2016-
// should never get here, but if it does:
2017-
return gdk_screen_get_primary_monitor(screen);
2018-
}
2019-
2020-
20211839
/* ------- have_menu == true and sizing ---------- */
20221840

20231841
// hack for windows (gtk < 3.12) - the 65 below is the taskbar height. Hack!!
@@ -2186,8 +2004,8 @@ gboolean shoes_app_gtk_configure_menu(GtkWidget *widget, GdkEvent *evt, gpointer
21862004
}
21872005
} else {
21882006
#ifdef SZBUG
2189-
printf(stderr, "shoes_app_gtk_configure_menu: dragged %d, %d, %d, %d\\n",
2190-
evt->configure.x, evt->configure.y, evt->configure.width, evt->configure.height);
2007+
fprintf(stderr, "shoes_app_gtk_configure_menu: dragged %d, %d, %d, %d\\n",
2008+
evt->configure.x, evt->configure.y, evt->configure.width, evt->configure.height);
21912009
GtkWidget *content = app->os.shoes_window;
21922010
#endif
21932011
}

0 commit comments

Comments
 (0)