当用户在任何窗口小部件外部或在不希望键盘焦点的窗口小部件上单击时,是否可以将键盘焦点移动到主窗口。我试过了
gboolean Window::Impl::mouse_down(GtkWidget* widget,GdkEventButton* event,void* user_data)
{
auto self=reinterpret_cast<Impl*>(user_data);
auto w=gtk_window_get_focus(GTK_WINDOW(widget));
if(w!=NULL)
{self->r_focus_old=w;}
gtk_window_set_focus(GTK_WINDOW(widget),NULL);
return FALSE;
}
此类作品,例外情况:
TRUE
连接到它的鼠标处理程序的窗口小部件时,它没有反应为了澄清,我想要一个网页的基本行为:如果用户在输入字段外单击,它会将其焦点丢失到容器。
当没有其他小部件拥有键盘时,这是需要调用的回调:
void Application::keyDown(Anja::Window& win,int scancode,Anja::keymask_t keymask,int id)
{
if(m_engine && !m_keystate[scancode])
{
auto note=scancodeToMIDI(scancode);
if(note!=0xff)
{
auto slot=scancodeToSlot(scancode);
m_engine->messagePost(MIDI::Message
{
MIDI::StatusCodes::NOTE_ON
,static_cast<int>(m_session.waveformGet(slot).channel())
,note
,127
});
}
else
{
auto ch=scancodeToChannel(scancode);
if(ch>=0 && ch<16)
{
if(m_keystate[Keys::FADE_IN])
{m_engine->fadeIn(ch,m_session.channel(ch).fadeTime());}
else
if(m_keystate[Keys::FADE_OUT])
{m_engine->fadeOut(ch,m_session.channel(ch).fadeTime());}
else
if(m_keystate[Keys::FADE_IN_FAST])
{m_engine->fadeIn(ch,1e-3f);}
else
if(m_keystate[Keys::FADE_OUT_FAST])
{m_engine->fadeOut(ch,1e-3f);}
}
else
{
switch(scancode)
{
case Keys::AUDITION:
{
auto slot_current=m_session.slotActiveGet();
assert(slot_current>=0 && slot_current<128);
note=slotToMIDI(slot_current);
m_engine->messagePost(MIDI::Message{MIDI::StatusCodes::NOTE_ON,0,note|0x80,127});
}
break;
case Keys::KILL_ALL:
for(size_t k=0;k<ChannelMixer::length();++k)
{m_engine->messagePost(MIDI::Message{MIDI::ControlCodes::SOUND_OFF,static_cast<int>(k),0});}
break;
}
}
}
}
m_keystate[scancode]=1;
}