Ejemplo n.º 1
0
static void rime_with_ibus() {
    ibus_init();
    IBusBus *bus = ibus_bus_new();
    g_object_ref_sink(bus);

    if (!ibus_bus_is_connected(bus)) {
        g_warning("not connected to ibus");
        exit(0);
    }

    g_signal_connect(bus, "disconnected", G_CALLBACK(ibus_disconnect_cb), NULL);

    IBusConfig *config = ibus_bus_get_config(bus);
    if (!config) {
        g_warning("ibus config not accessible");
    }
    else {
        g_object_ref_sink(config);
        ibus_rime_load_settings(config);
        g_signal_connect(config, "value-changed",
                         G_CALLBACK(ibus_rime_config_value_changed_cb), NULL);
    }

    IBusFactory *factory = ibus_factory_new(ibus_bus_get_connection(bus));
    g_object_ref_sink(factory);

    ibus_factory_add_engine(factory, "rime", IBUS_TYPE_RIME_ENGINE);
    if (!ibus_bus_request_name(bus, "com.googlecode.rimeime.Rime", 0)) {
        g_error("error requesting bus name");
        exit(1);
    }

    if (!notify_init("ibus-rime")) {
        g_error("notify_init failed");
        exit(1);
    }

    RimeSetupLogging("rime.ibus");

    gboolean full_check = FALSE;
    ibus_rime_start(full_check);

    ibus_main();

    RimeFinalize();
    notify_uninit();

    if (config) {
        g_object_unref(config);
    }
    g_object_unref(factory);
    g_object_unref(bus);
}
Ejemplo n.º 2
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	// 防止服务进程开启输入法
	ImmDisableIME(-1);

	HRESULT hRes = ::CoInitialize(NULL);
	// If you are running on NT 4.0 or higher you can use the following call instead to 
	// make the EXE free threaded. This means that calls come in on a random RPC thread.
	//HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	RimeSetupLogging("rime.weasel");

	// command line option /q stops the running server
	bool quit = !wcscmp(L"/q", lpstrCmdLine) || !wcscmp(L"/quit", lpstrCmdLine);
	//bool restart = !wcscmp(L"/restart", lpstrCmdLine);
	//if (quit || restart)
	{
		weasel::Client client;
		if (client.Connect())
			client.ShutdownServer();
		if (quit)
			return 0;
	}

	int nRet = 0;
	try
	{
		WeaselServerApp app;
		nRet = app.Run();
	}
	catch (...)
	{
		// bad luck...
		nRet = -1;
	}

	_Module.Term();
	::CoUninitialize();

	return nRet;
}
Ejemplo n.º 3
0
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);

	HRESULT hRes = ::CoInitialize(NULL);
	// If you are running on NT 4.0 or higher you can use the following call instead to 
	// make the EXE free threaded. This means that calls come in on a random RPC thread.
	//HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	ATLASSERT(SUCCEEDED(hRes));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	::DefWindowProc(NULL, 0, 0, 0L);

	AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

	hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	RimeSetupLogging("rime.weasel");

	CreateDirectory(WeaselUserDataPath().c_str(), NULL);

	int ret = 0;
	HANDLE hMutex = CreateMutex(NULL, TRUE, L"WeaselDeployerExclusiveMutex");
	if (!hMutex)
	{
		ret = 1;
	}
	else if (GetLastError() == ERROR_ALREADY_EXISTS)
	{
		ret = 1;
	}
	else
	{
		ret = Run(lpCmdLine);
	}
	
	if (hMutex)
	{
		CloseHandle(hMutex);
	}
	_Module.Term();
	::CoUninitialize();

	return ret;
}